Can feature

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

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord