Originally posted @ https://codeanddeploy.com visit and download the sample code: https://codeanddeploy.com/blog/laravel/how-to-create-a-custom-dynamic-middleware-for-spatie-laravel-permission In this post, I'm sharing how to create a custom middleware for spatie Laravel permission. In my previous post, I shared how to implement the Laravel 8 user roles and permissions using spatie. Now I let's do a separate post about how to create custom middleware for your permission.

Route::group(['middleware' => ['auth', 'permission']], function() { //your restricted routes here }); }); As you can see we added the 'permission' middleware to our restricted group routes.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners