From the course: Advanced Laravel
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Write custom middleware - Laravel Tutorial
From the course: Advanced Laravel
Write custom middleware
- [Instructor] Now, our users are redirected to their respective dashboards, like our instructor here can view an instructor dashboard. But nothing is stopping this instructor from accessing the member's dashboard by directly typing in the URL, like so. See, we are able to do this, but this should not be allowed. So how do we restrict our users from accessing routes they're not supposed to? The same way we restrict users who are not logged in to view a logged in user's route using a middleware. We now need to create a custom middleware. First, let me log out and let's create a custom middleware, sail artisan make middleware, and call it something like check user role. Middleware is created. Open it. Now, if you can recall what a middleware does, it acts like a security guard that checks the incoming request, perform some action here before allowing them to proceed to the application or another middleware. In here, we have…