maize-tech/laravel-nova-eloquent-sortable
Composer 安装命令:
composer require maize-tech/laravel-nova-eloquent-sortable
包简介
Laravel Nova Eloquent Sortable
README 文档
README
Easily add inline sortable actions to any resource in Laravel Nova.
This package is heavily based on Spatie's Eloquent Sortable. Please make sure to read its documentation and installation guide before proceeding!
Installation
You can install the package via composer:
composer require maize-tech/laravel-nova-eloquent-sortable
You can publish the config file with:
php artisan vendor:publish --tag="nova-eloquent-sortable-config"
This is the contents of the published config file:
return [ /* |-------------------------------------------------------------------------- | See sortable action permission |-------------------------------------------------------------------------- | | Here you may specify the fully qualified class name of the invokable class | used to determine whether a user can see sortable actions or not. | If null, all users who have access to Nova will have the permission. | */ 'can_see_sortable_action' => null, /* |-------------------------------------------------------------------------- | Run sortable action permission |-------------------------------------------------------------------------- | | Here you may specify the fully qualified class name of the invokable class | used to determine whether a user can sort a given model or not. | If null, all users who have access to Nova will have the permission. | */ 'can_run_sortable_action' => null, ];
Usage
To use the package, add the Maize\NovaEloquentSortable\HasEloquentSortable trait to the nova resource where you want to have marks:
use Laravel\Nova\Resource; use Maize\NovaEloquentSortable\HasEloquentSortable; class MyResource extends Resource { use HasEloquentSortable; }
Once done, all you have to do is include all the actions you need for the given resource:
use Maize\NovaEloquentSortable\Actions\MoveOrderDownAction; use Maize\NovaEloquentSortable\Actions\MoveOrderUpAction; use Maize\NovaEloquentSortable\Actions\MoveToEndAction; use Maize\NovaEloquentSortable\Actions\MoveToStartAction; public function actions(NovaRequest $request) { return [ MoveOrderDownAction::make(), MoveToEndAction::make(), MoveOrderUpAction::make(), MoveToStartAction::make(), ]; }
You can also include the custom OrderColumn field, which allows you to show the order of each entity when indexing them:
use Maize\NovaEloquentSortable\Fields\OrderColumn; public function fields(NovaRequest $request) { return [ OrderColumn::new('Order', static::class), ]; }
Available Actions
MoveOrderDownAction
The MoveOrderDownAction inline action moves the given model down by a single position.
The action is automatically hidden when the model is already in the last position.
MoveToEndAction
The MoveToEndAction inline action moves the given model to the last position.
The action is automatically hidden when the model is already in the last position.
MoveOrderUpAction
The MoveOrderUpAction inline action moves the given model up by a single position.
The action is automatically hidden when the model is already in the first position.
MoveToStartAction
The MoveToStartAction inline action moves the given model to the first position.
The action is automatically hidden when the model is already in the first position.
Define a custom visibility
By default, all users who have access to Laravel Nova will be able to see all included sort actions.
If you want to restrict their visibility for some users, you can define a custom CanSeeSortableAction invokable class.
Here's an example class checking user's permissions:
use Laravel\Nova\Http\Requests\NovaRequest; class CanSeeSortableAction { public function __invoke(NovaRequest $request): bool { return $request->user()->can('sort_models'); } }
Once done, all you have to do is reference your custom class in can_see_sortable_action attribute under config/nova-eloquent-sortable.php:
'can_see_sortable_action' => \Path\To\CanSeeSortableAction::class,
Define a custom run permission
By default, all users who have access to Laravel Nova will be able to run all included sort actions.
If you want to restrict the permission for some users, you can define a custom CanRunSortableAction invokable class.
Here's an example class checking user's permissions:
use Illuminate\Database\Eloquent\Model; use Laravel\Nova\Http\Requests\NovaRequest; class CanRunSortableAction { public function __invoke(NovaRequest $request, Model $model): bool { return $request->user()->can('sort_model', $model); } }
Once done, all you have to do is reference your custom class in can_run_sortable_action attribute under config/nova-eloquent-sortable.php:
'can_run_sortable_action' => \Path\To\CanRunSortableAction::class,
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
maize-tech/laravel-nova-eloquent-sortable 适用场景与选型建议
maize-tech/laravel-nova-eloquent-sortable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.23k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2022 年 10 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sortable」 「nova」 「laravel」 「eloquent」 「maize-tech」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maize-tech/laravel-nova-eloquent-sortable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maize-tech/laravel-nova-eloquent-sortable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maize-tech/laravel-nova-eloquent-sortable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
Easily provide front-end sorting controls for SilverStripe lists
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
Sortable models for Laravel Eloquent ORM.
统计信息
- 总下载量: 2.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-10
