Search code examples
laravellaravel-5acl

show or hide a button based on user role in laravel


I have two roles in my web app 1-employee 2-scrum master i want to hide some buttons for the normal employee and only show it for the scrum master in the same view is there any simple way to do it...thanks in advance


Solution

  • I don't know about laravel's Standard Method but You have to use If Condition anyways! So, Here is the Quick Solution that I use.

    @if(Auth::user()->user_role == "role")
        // Show Button <button>...</button>
    @endif
    

    This is what I do when I have to show some information to users having specific roles and hide from other users.

    Let me know if Helps!