课程: Advanced Laravel

今天就学习课程吧!

今天就开通帐号,24,100 门业界名师课程任您挑!

Write custom middleware

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…

内容