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.