Laravel Blade check user role

lewis4u

In laravel Blade templating we can exclude some parts of HTML with this code:

        @if (Auth::user())
            <li><a href="{{ url('/home') }}">Mein Profil</a></li>
            <li><a href="{{ url('/admin') }}">Admin</a></li>
        @else
            <li><a href="{{ url('/home') }}">Mein Profil</a></li>
        @endif

If user is authenticated then show home and admin links and if user is not authenticated then show only home link.

My question is how to make a check here if user is admin?

I have default login system from laravel and i just added one more column in table users -> ('admin') with tinyint value 1 and in this video https://www.youtube.com/watch?v=tbNKRr97uVs i found the code for checking if user is admin

 if (!Auth::guest() && Auth::user()->admin )

and it works in AdminMiddleware.php but it doesn't work in blade. How to make this working??

lewis4u
            @if (!Auth::guest() && Auth::user()->admin)
                <li><a href="{{ url('/home') }}">Mein Profil</a></li>
                <li><a href="{{ url('/admin') }}">Admin</a></li>
            @else
                <li><a href="{{ url('/home') }}">Mein Profil</a></li>
            @endif      

this works just to be cleared (just add one more column tinyint 'admin' in user table and set to 1)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related