Laravel Pro Tips
Laravel Tip 💡
When you want to share the same route based on user role, you can use a middleware to bind the suitable controller conditionally to an alias and then use it in the route closure. #Laravel
Mhamed Talhaouy 🪐
How to implement multi-login redirections in @laravelphp, you can use middleware to check the user's role and redirect them to the appropriate page
If your user only has a role of admin or user, you can create a column of 'is_admin' (boolean type) in the users table and create a custom middleware to check if user is admin or not.
Laravel Tip 💡 Did you know you can enrich request data using a middleware? For example, resolve the user origin country using their IP and add the country abbreviation to the request.
You can exclude middleware at the route level in Laravel using the withoutMiddleware method.
Jan 12th, 2023
Laravel Middleware: Put in Routes, Controller, or Elsewhere? (4 Options)
If you have a Middleware, where you should use it: in the Routes file or in the Controller? Here are the FOUR options.