nova-kit/helpers
Composer 安装命令:
composer require nova-kit/helpers
包简介
Useful helpers for Laravel Nova
README 文档
README
Installation
To install through composer, run the following command from terminal:
composer require "nova-kit/helpers"
Usages
Eloquent
Get Qualified Column Name
NovaKit\column_name(string|\Illuminate\Database\Eloquent\Model $model, string $attribute): string;
The function generate qualified column name for an eloquent model:
use function NovaKit\column_name; return column_name(App\Models\User::class, 'email');
Eloquent Exists
NovaKit\eloquent_exists(\Illuminate\Database\Eloquent\Model|mixed $model): bool;
The function checks if given $model is an instance of Illuminate\Database\Eloquent\Model and it exists in the database:
use App\Models\User; use function NovaKit\eloquent_exists; $user = User::find(5); return eloquent_exists($user);
Get Table Name
NovaKit\table_name(string|\Illuminate\Database\Eloquent\Model $model): string;
The function generate table name for an eloquent model:
use function NovaKit\table_name; return table_name(App\Models\User::class);
Nova Request Helpers
Has Ordering
NovaKit\has_ordering(\Laravel\Nova\Http\Requests\NovaRequest $request): bool;
Determine if current Request has any ordering.
use Laravel\Nova\Http\Requests\NovaRequest; use function NovaKit\has_ordering; public static function indexQuery(NovaRequest $request, $query) { if (! has_ordering($request)) { $query->orderBy('name'); } }
Running Action
NovaKit\running_action(\Illuminate\Http\Request $request, ?string $action): bool;
Determine NovaRequest is currently Running an Action Request.
use Illuminate\Http\Request; use Laravel\Nova\Http\Requests\NovaRequest; public function authorizedToUpdate(Request $request) { if (running_action($request, 'open-on-platform')) { return $request->user()->canModerateResources(); } return $this->authorizedTo($request, 'update'); }
Common Helpers
Validate Column Name
NovaKit\is_column_name(mixed $column): bool;
Validate if given $column is a valid column name.
use function NovaKit\is_column_name; if (is_column_name($request->query('sortBy'))) { $query->latest($request->query('sortBy')); }
Safe Integer
NovaKit\safe_int(mixed $value): int|string;
Convert large id higher than JavaScript's Number.MAX_SAFE_INTEGER to string.
use function NovaKit\safe_int; return safe_int(9007199254741001); // will return "9007199254741001"
Schemaless URL
NovaKit\schemaless_url(string $url): string;
Get schemaless URL for given $url
use function NovaKit\schemaless_url; return schemaless_url('https://github.com'); // will return "github.com"
统计信息
- 总下载量: 224
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-04-01