Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5: Change navbar if user is logged

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, Logout, Profile, etc... and a Login button otherwise.

Any help on how I could address this the right way is greatly appreciated. This is what I'm considering at the moment:

  • A User object is always passed to the view.
  • The view checks if the User is set (meaning it's logged in) to include the appropriate partial blade template for the navbar.

app.blade.php:

... @if (isset($user))      @include('partials.navbarlogged')  @else      @include('partials.navbar') ... 

Is this the best method? Thanks for your time!

like image 279
bockzior Avatar asked Mar 29 '15 18:03

bockzior


1 Answers

If you are using Laravel 5's built in User model you can simply do

@if (Auth::check())   //show logged in navbar @else   //show logged out navbar @endif 
like image 151
Jacob Avatar answered Sep 22 '22 19:09

Jacob