Modifying the Navbar to allow for User Login Links

Create a new file in resources\views\layouts called navAuth.blade.php use the following code

<ul class="nav navbar-nav pull-right"> 
    <li><a href="#register">Register</a></li> 
    <li><a href="#Login">Login</a></li> 
    <li><a href="#Logoff">Logoff</a></li> 
</ul>

Now modify your parent view - resources/views/layouts/app.blade.php - add in the line highlighted in red below in order to pull-in the new login links on your navbar

Now when you view the navbar you should see three new menu items on the right of the navbar. Modify these menu items so that they navigate to the correct routes. Use

php artisan route:list

To remind yourself of what the necessary route names are for the appropriate navbar links.

Next modify your new navbar file so that the Login and Register nav links will only be displayed if the User is not already Logged in and that the Logout nav link will only be displayed if the user is logged in. Use the Laravel blade directive @if and the fuction Auth::guest( ) for this purpose.

Next modify the Register/Login and Logout nav links so that they display an appropriate bootstrap glyphicon for each link. Bootstrap glyphicons are here https://getbootstrap.com/docs/3.3/components/

Your navAuth.blade.php file will now look something like the following

Now you register and login nav links will only display if you are a guest - i.e. not logged in. Your logout nav link will only display if you are logged in.

Leave a Reply