@@ -30,20 +30,33 @@ This is the contents of the published config file:
30
30
31
31
``` php
32
32
return [
33
+
33
34
/*
34
35
|--------------------------------------------------------------------------
35
- | Sortable permission action
36
+ | See sortable action permission
36
37
|--------------------------------------------------------------------------
37
38
|
38
39
| 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.
41
41
| If null, all users who have access to Nova will have the permission.
42
42
|
43
43
*/
44
44
45
45
'can_see_sortable_action' => null,
46
46
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
+
47
60
];
48
61
```
49
62
@@ -71,10 +84,10 @@ use Maize\NovaEloquentSortable\Actions\MoveToStartAction;
71
84
public function actions(NovaRequest $request)
72
85
{
73
86
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( ),
78
91
];
79
92
}
80
93
```
@@ -127,7 +140,7 @@ The action is automatically hidden when the model is already in the first positi
127
140
128
141
By default, all users who have access to Laravel Nova will be able to see all included sort actions.
129
142
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.
131
144
132
145
Here's an example class checking user's permissions:
133
146
@@ -136,7 +149,7 @@ use Laravel\Nova\Http\Requests\NovaRequest;
136
149
137
150
class CanSeeSortableAction
138
151
{
139
- public function __invoke(NovaRequest $request, $model = null, $resource = null ): bool
152
+ public function __invoke(NovaRequest $request): bool
140
153
{
141
154
return $request->user()->can('sort_models');
142
155
}
@@ -149,6 +162,33 @@ Once done, all you have to do is reference your custom class in `can_see_sortabl
149
162
'can_see_sortable_action' => \Path\To\CanSeeSortableAction::class,
150
163
```
151
164
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
+
152
192
## Testing
153
193
154
194
``` bash
0 commit comments