How to apply for a user role in Laravel web application based on user activities with Azure AD (Login) and ms graph ( Microsoft Graph)?

Md Jamil Uddin 41 Reputation points
2022-08-05T14:09:43.047+00:00

Hi,

I am new to Laravel. I have a Laravel web app (SchoolApp) registered on the Azure AD (App registrations).
I have 3 user roles: Admin, Teacher, and student. I need to restrict some nav menus base on the user role.
How can I do that?
Can somebody guide me in the correct code? please?

Code: restrict for Teacher and student

@if(isset($userName))

        <li class="nav-item" data-turbolinks="false">  
          <a class="navbar-brand d-flex align-items-center" href="{<!-- -->{ url('/registration_view') }}">  
                  {<!-- -->{ __(' User registration ') }}  
          </a>  
        </li>  

@endif

Code: restrict for student

@if(isset($userName))

        <li class="nav-item" data-turbolinks="false">  
          <a class="navbar-brand d-flex align-items-center" href="{<!-- -->{ url('/Report_view') }}">  
                  {<!-- -->{ __(' student Report ') }}  
          </a>  
        </li>  

@endif

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Shweta Mathur 30,296 Reputation points Microsoft Employee Moderator
    2022-08-12T05:44:46.05+00:00

    Hi @Md Jamil Uddin ,

    Thanks for reaching out.

    I understand you are looking for role-based authentication and authorization in Laravel web application.

    In this role-based authentication in Laravel, middleware is used to control user access as follows

    php artisan make:middleware CheckRole

    Different views or pages need to call based on User Role as mentioned in this blog post.

    Regarding roles and permissions, you can check it in azure (as scopes) or base it on your application's permissions. Refer Laravel's middleware.

    Hope this will help.

    Thanks,
    Shweta

    -----------------------------------------

    Please remember to "Accept Answer" if answer helped you.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.