Laravel Blade PHP - How to use @if statements to display different links -
i'm making site using laravel , i'm trying display different links in navigation bar if users logged in.
here's code far:
@if (auth::check()) <li><a href="/profile">profile</a></li> <li><a href="/auth/logout">logout</a></li> @else <li><a href="/auth/login">login</a></li> <li><a href="/auth/register">register</a></li>
do need
use auth;
or in php file.
all appreciated.
this taken directly 1 of laravel's older defaut views used bootstrap
:
<ul class="nav navbar-nav navbar-right"> @if (auth::guest()) <li><a href="{{ url('/auth/login') }}">login</a></li> <li><a href="{{ url('/auth/register') }}">register</a></li> @else <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ auth::user()->name }} <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="{{ url('/auth/logout') }}">logout</a></li> </ul> </li> @endif </ul>
you'll want use @if (auth::guest())
also, sure include @endif
required blade's @if
.
Comments
Post a Comment