0% found this document useful (0 votes)
8 views45 pages

Laravel - Middleware

Middleware in Laravel is a feature that allows for security checks on page access based on user roles, such as admin, member, and super admin. The document outlines the steps to create a project, update the user table, create middlewares, and set up views and routes for login functionality. It emphasizes the importance of role verification to control access to different web pages after user login.

Uploaded by

toyan40946
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views45 pages

Laravel - Middleware

Middleware in Laravel is a feature that allows for security checks on page access based on user roles, such as admin, member, and super admin. The document outlines the steps to create a project, update the user table, create middlewares, and set up views and routes for login functionality. It emphasizes the importance of role verification to control access to different web pages after user login.

Uploaded by

toyan40946
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Laravel : Middleware

Contents
 What is middleware in Laravel?
 Create middlewares to restrict access to web-pages
What is middleware in laravel?
Middleware is a feature of laravel which allows to add security checks on the access of a page,
 Admin can access only admin related pages
 Member can access only member related pages
 Super Admin can access only super admin related pages
Steps
1. create a project
2. update user table script and add role field
3. run migration command
4. create middlewares
5. create views
6. update routes file
>> cd E:\xampp\htdocs\testmiddleware
>> php artisian migrate
Check from phpmyadmin if table
is added in databases
Update User model
 Add role field
Views for login functionality
Add routes for login
Laravel has build in controller for authentication process
Create three accounts with
different roles
 admin
 member
 superadmin
Create middlewares
cd xampp/htdocs/testmiddleware
>> php artisan make:middleware adminmiddleware
>> php artisan make:middleware membermiddleware
>> php artisan make:middleware superadminmiddleware
Register middlewares in
Kernal.php
 There are three middlewares [admin, superadmin, member]
 Each one will determine access to different users
Create view ‘unauthorized’
Control Access towards
webpages using middlewares
How these middleware will
work?
 After logging in,
 User’s role is checked by the middleware
 Than inner route will execute
Create controller
>> cd E:\xampp\htdocs\middleware_auth
>> php artisian make:controller homecontroller
Create view ‘middleware’
Check if logged user is ‘admin’
or ‘member’ or ‘superadmin’
Thank you!

You might also like