Category: Laravel, PHP

In this tutorial, we shall have a project named ‘mystore’, which can have 2 kinds of users, either ‘admin’ or ‘seller’. Also, the routes should be protected, meaning, the logged in user should not be able to access the dashboard or any of the inside pages of the other role, even if they type the URL in the browser.

You can now go to your browser, and try logging in with the admin and seller accounts, and you will be redirected to the respective dashboards.

In the folder mystore/app/Http/Middleware create a new file Role.php, and add the following code for role check

Now go back to your browser, log in as seller role and try opening the dashboard of the admin role (and vice versa), it should redirect to the given route that is /home.
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