Previous Video: [ Ссылка ]
In Part 8, we protect our admin routes. In video, we protect our dashboard route so that no one can access it without logging into admin.
There are two approaches to protect our routes :-
1) With Sessions
2) With Middleware
1) With Sessions :- We have started admin session at the time of successful login and then compared that Session variable in every admin function like in dashboard function in our case. This approach is the simplest approach that we used in most cases.
In AdminController.php file, we have modified our login function. We have added adminSession at the time of Successful login. We have used Session::put method for creating the Session variable adminSession and assigned username to it. Then we have compared this in dashboard function to check if adminSession exists or not. If exists then would execute dashboard tasks otherwise would redirect back to admin login.
See in video, after implementing this approach, "Please login to access" message has come when we tried to access dashboard page without login.. we couldn't able to access dashboard page directly.
We have also done it with our 2nd way i.e. with Middleware
2) Middleware :- Middleware we basically use for User's authentication in Laravel. So here we have used for our Admin authentication, you can say protection.
We have added Route::group syntax in our Route file "web.php" that contain all our admin routes that needs protection.
Also, we have made changes in RedirectifAuthenticated.php file of Laravel from where we have redirected to our login page if we directly tried accessing any admin page like dashboard without logging in.
In video, We have disabled our earlier approach and then done with this Middleware approach successfully. No need to make any changes in functions now..
See in video, we have done with it as well..
Hope everything is clear. Please share your views and ask if something not clear..
Thanks for watching :) Stay tune for next video..
Next Video | Part 9: [ Ссылка ]
![](https://i.ytimg.com/vi/6kIqINVNS30/maxresdefault.jpg)