iiCe89's avatar

Hide/show button on user login

Hi , how would i go about showing a button in my navbar if user is logged in ? and hidden if not ? i have a Dashboard page but i don't want everybody to see it unless they are logged in?

0 likes
8 replies
Swaz's avatar
Swaz
Best Answer
Level 20
@if (Auth::check())
    // The user is logged in...
@endif
@if (Auth::guest())
    // The user is not logged in...
@endif
ohffs's avatar

Something like :

@if (Auth::check())
  <your button>
@endif 

Edit: beaten too it ;-)

1 like
iiCe89's avatar

would this go in the Blade ? ?

cviv's avatar

Here

@if(Auth::user())
<button>I'm logged in</button>
@else
<button>I'm not logged in </button>
@endif

edit: sorry can find backtick on iphone

1 like
iiCe89's avatar

I have done like this i assume not correct as its not showing ?

<div id="navbar" class="navbar-collapse collapse">
            @if (Auth::user())
            <ul class="nav navbar-nav navbar-left" style="margin-top:12px;">
                <li><span class="label label-danger"><i class="fa fa-exclamation-triangle" style="color:#ffff33" aria-hidden="true"></i> Currently Beta Version 1.0</span></li>
                <li><a href="/dashboard">Return to Dashboard</a></li>
            </ul>
            @endif
            @if (Auth::guest())
             <ul class="nav navbar-nav navbar-left" style="margin-top:12px;">
                <li><span class="label label-danger"><i class="fa fa-exclamation-triangle" style="color:#ffff33" aria-hidden="true"></i> Currently Beta Version 1.0</span></li>
            </ul>
            @endif
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/"><i class="fa fa-home" data-toggle="modal" data-target="#Userlogin" aria-hidden="true"></i> Home</a></li>
                <li><a href="/about"><i class="fa fa-diamond" data-toggle="modal" data-target="#Userlogin" aria-hidden="true"></i> About Signl</a></li>
            </ul>
        </div><!--/.nav-collapse -->
iiCe89's avatar

Apologies fixed ! was looking at wrong blade lol , i have multiple navs

Please or to participate in this conversation.