If you are running Laravel v8.70
, you can chain can()
method directly instead of middleware('can:..')
1// instead of 2Route::get('users/{user}/edit', function (User $user) { 3 ... 4})->middleware('can:edit,user'); 5 6// you can do this 7Route::get('users/{user}/edit', function (User $user) { 8 ... 9})->can('edit' 'user');10 11// PS: you must write UserPolicy to be able to do this in both cases
Tip given by @sky_0xs