Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Laravel Breeze with User Role Areas
Rating: 4.4 out of 5(10 ratings)
31 students

Laravel Breeze with User Role Areas

Learn how to define separate areas for users based on User Roles: Admin, Teacher and Student
Created byTapan Sharma
Last updated 3/2024
English

What you'll learn

  • Learn how to create separate Areas/Sections for different users based on Roles
  • Define separate layouts/views/controllers/namespaces/route prefixes/navigation menu etc for different roles
  • Learn how to define a flexible middleware to check for Roles existance and provide access accordingly
  • Learn how to group Routes based on roles and implement a flexible routing structure

Course content

2 sections14 lectures1h 20m total length
  • Install and Setup Laravel/Breeze4:09

    Install a fresh Laravel project, set up Breeze with Blade and Alpine, and configure the Breeze role areas database; prepare models and migrations for different user roles.

  • Let's Define the Models/Migrations/Pivot Tables6:31

    Define the role and permission models and migrations, establish pivot tables (permission_role, role_user), enforce unique role titles, and implement belongs to many relationships with the users table.

  • Define the Seeders for User/Role/Pivot Tables7:59

    Define and run seeders for users, roles, and the user role pivot to initialize admin, teacher, and student accounts with their roles.

  • Let's Start working on the Student Dashboard7:44

    Create a dedicated student dashboard by extending Laravel Breeze layouts, adding a student layout, navigation, and a student dashboard blade.

  • Finalize the Student Dashboard4:35
  • Let's Define a Separate Section for Teachers4:46

    Create a dedicated teacher section in Laravel Breeze by duplicating the student setup, defining teacher routes, controllers, views, and layouts, and testing role-based redirects to the teacher dashboard.

  • Auto Redirect to Correct Area after Login7:23

    Redirect users to their respective dashboards based on their roles (admin, teacher, student) after login by implementing a get redirect route name method and role checks in Laravel Breeze.

  • Define a Flexible Middleware to Restrict Role Areas9:33

    Define a flexible role middleware in Laravel Breeze to restrict student and teacher dashboards by checking the authenticated user's roles using a has role method and returning 403 forbidden response.

  • Let's Work on the Admin Area6:04

    Set up the admin area by creating an admin route, an invokable dashboard controller, and admin blade layouts with role-based middleware to enable admin access.

  • Let's Refactor the Routes6:38

    Refactor routes by grouping similar routes with middleware and role-based prefixes, auto-building names like student.dashboard, and adding redirects to dashboards for student, teacher, and admin, and preparing namespace-based controller organization.

  • Quick trick for Importing Multiple Controllers from the same Namespace2:43

    Streamline imports by using a single namespace import to dynamically load multiple controllers for student, admin, and teacher areas. Assign a default role to users on registration.

  • Assign Default Role of Student on Registration7:28

    Assign a default student role to new users on registration by handling the register event with a listener that attaches the student role to the user, enabling immediate dashboard access.

  • Make Dashboard Route Dynamic on Welcome Page2:38

    dynamically route the welcome page dashboard link to the appropriate dashboard based on the authenticated user's role, using the get redirect route name method and the route helper.

Requirements

  • Beginner Knowledge of Laravel is Required.

Description

In this course, we will learn how to define different areas based on User Roles: Students, Teachers, and Admins.

The goal is to show you how to separate those subsystems in a Laravel-structured way.

And, along the way, we'll learn the following topics:

  • Learn how to create separate Areas/Sections for different users based on Roles

  • Define separate layouts/views/controllers/namespaces/navigation menu etc for different roles

  • Define a flexible middleware to check for Roles' existence and properly implement Authorization checks.

  • Learn how to group Routes based on roles and implement a flexible routing structure along with route name prefixes and URLs


Miscellaneous Features:

  • Implement a method to automatically redirect to the correct dashboard based on the User Role.

  • Learn how to assign a default student role on registration.

  • Learn how to define seeders for each model that would configure our project ready for production.

All the role areas that we define in this course will have a separate:

  • Controller subfolders/namespaces

  • Views subfolders

  • Visual layouts

  • Navigation menus

  • Route groups

  • Route name prefixes

  • URL prefixes


Summary: This course will teach you how to define separate areas based on the User Roles, with separate routes/views/layouts/navigation menus/URL prefixes and route groups along with proper Authorization checks .

We will create a simple project without any logic inside, and without separate visual themes, the goal is to teach you how to divide the Laravel structure into role areas.

Who this course is for:

  • Laravel Developers who want to define separate areas based on Roles