Auth Facade in layouts/app.blade.php

Posted 3 years ago by lucaspoignon

Hi

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).

            @if(auth()->guard('apotheker')->check())
                <p>test</p>
            @endif

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>
                        </a>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="{{ url('/logout') }}"><i class="fa fa-btn fa-sign-out"></i>Logout</a></li>
                        </ul>
                    </li>

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