Laravel 5: Change navbar if user is logged

后端 未结 6 460
盖世英雄少女心
盖世英雄少女心 2021-02-03 18:57

I\'m completely new to Laravel, MVC and templating engines in general.

I need to show certain navbar buttons and options if a user is logged in such as: Notifications, L

6条回答
  •  你的背包
    2021-02-03 19:40

    For laravel 5.7 and above, use @auth and @guest directives.Here is the official documentation here

    @auth
       // The user is authenticated...
    @endauth
    @guest
       // The user is not authenticated...
    @endguest
    

    You may specify the authentication guard that should be checked when using the @auth and @guest directives:

    @auth('admin')
        // The user is authenticated...
    @endauth
    
    @guest('admin')
        // The user is not authenticated...
    @endguest
    

    Otherwise, you can use the @unless directive:

    @unless (Auth::check())
        You are not signed in.
    @endunless
    

提交回复
热议问题