@@ -30,20 +30,33 @@ This is the contents of the published config file:
3030
3131``` php
3232return [
33+
3334 /*
3435 |--------------------------------------------------------------------------
35- | Sortable permission action
36+ | See sortable action permission
3637 |--------------------------------------------------------------------------
3738 |
3839 | Here you may specify the fully qualified class name of the invokable class
39- | used to determine whether a user can see and perform sorts to a given model
40- | or not.
40+ | used to determine whether a user can see sortable actions or not.
4141 | If null, all users who have access to Nova will have the permission.
4242 |
4343 */
4444
4545 'can_see_sortable_action' => null,
4646
47+ /*
48+ |--------------------------------------------------------------------------
49+ | Run sortable action permission
50+ |--------------------------------------------------------------------------
51+ |
52+ | Here you may specify the fully qualified class name of the invokable class
53+ | used to determine whether a user can sort a given model or not.
54+ | If null, all users who have access to Nova will have the permission.
55+ |
56+ */
57+
58+ 'can_run_sortable_action' => null,
59+
4760];
4861```
4962
@@ -71,10 +84,10 @@ use Maize\NovaEloquentSortable\Actions\MoveToStartAction;
7184public function actions(NovaRequest $request)
7285{
7386 return [
74- MoveOrderDownAction::for($this ),
75- MoveToEndAction::for($this ),
76- MoveOrderUpAction::for($this ),
77- MoveToStartAction::for($this ),
87+ MoveOrderDownAction::make( ),
88+ MoveToEndAction::make( ),
89+ MoveOrderUpAction::make( ),
90+ MoveToStartAction::make( ),
7891 ];
7992}
8093```
@@ -127,7 +140,7 @@ The action is automatically hidden when the model is already in the first positi
127140
128141By default, all users who have access to Laravel Nova will be able to see all included sort actions.
129142
130- If you want to restrict their visibility to some users, you can define a custom ` CanSeeSortableAction ` invokable class.
143+ If you want to restrict their visibility for some users, you can define a custom ` CanSeeSortableAction ` invokable class.
131144
132145Here's an example class checking user's permissions:
133146
@@ -136,7 +149,7 @@ use Laravel\Nova\Http\Requests\NovaRequest;
136149
137150class CanSeeSortableAction
138151{
139- public function __invoke(NovaRequest $request, $model = null, $resource = null ): bool
152+ public function __invoke(NovaRequest $request): bool
140153 {
141154 return $request->user()->can('sort_models');
142155 }
@@ -149,6 +162,33 @@ Once done, all you have to do is reference your custom class in `can_see_sortabl
149162'can_see_sortable_action' => \Path\To\CanSeeSortableAction::class,
150163```
151164
165+ ## Define a custom run permission
166+
167+ By default, all users who have access to Laravel Nova will be able to run all included sort actions.
168+
169+ If you want to restrict the permission for some users, you can define a custom ` CanRunSortableAction ` invokable class.
170+
171+ Here's an example class checking user's permissions:
172+
173+ ``` php
174+ use Illuminate\Database\Eloquent\Model;
175+ use Laravel\Nova\Http\Requests\NovaRequest;
176+
177+ class CanRunSortableAction
178+ {
179+ public function __invoke(NovaRequest $request, Model $model): bool
180+ {
181+ return $request->user()->can('sort_model', $model);
182+ }
183+ }
184+ ```
185+
186+ Once done, all you have to do is reference your custom class in ` can_run_sortable_action ` attribute under ` config/nova-eloquent-sortable.php ` :
187+
188+ ``` php
189+ 'can_run_sortable_action' => \Path\To\CanRunSortableAction::class,
190+ ```
191+
152192## Testing
153193
154194``` bash
0 commit comments