4 years ago

Auth Facade in layouts/app.blade.php

Posted 4 years ago by lucaspoignon


I am building a Laravel 5.2 application using multiple authentication. I have two types of accounts. User and Apotheker (Pharmacist in English). I used the standard auth:make() command to generate the standard views. I need to check in my view if the user is authenticated to show a logout button.

I tried this in my welcome.blade.php, and and it returns true ( because the Apotheker has logged in).


When I try to insert this code into app.blade.php in the directory layouts (the one Laravel generates for you), it gives me the following error.

    Trying to get property of non-object (View: /var/www/resources/views/layouts/app.blade.php) (View:                  /var/www/resources/views/layouts/app.blade.php)

My code in this file look like this:

                @if (Auth::guard('apotheker')->check())
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
                            {{ Auth::user()->name }} <span class="caret"></span>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="{{ url('/logout') }}"><i class="fa fa-btn fa-sign-out"></i>Logout</a></li>

Please sign in or create an account to participate in this conversation.