0

How to Restrict Laravel Controller Access to Authenticated Users

How to Restrict Laravel Controller Access to Authenticated Users.

In Laravel 5 we use middleware-driven solutions for restricting controller access to authenticated users. Laravel use two simple approach to accomplish this.

First approach is based on the routes, we add the middleware restriction with in our projects routes.php file. For instance we have a user dashboard function and we want allow access only authenticated users. To do this you can use the following code.

After that you see now only signed in user access the dashboard function or page.

Second approach is based on the controller, we add the middleware restriction within controller constructor to do this use the following code.

Sandeep Kumar

Sandeep kumar is a web developer and a professinal blogger. He works for latest technologies and write articles what he learn. In ICodeHub he share web languages tutorials and other programming tips and tricks. if you need some help or have some suggestion then mail him at sandeep92pal@gmail.com without any hesitation. He believes in learning and sharing.