Ad

The Default Authentication Function In Laravel Didnt Work, Logout Function Cant Show Up

- 1 answer

 @if (Auth::guest())
                    <li><a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{ url('/login') }}">Login</a></li>
                    <li><a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{ url('/register') }}">Register</a></li>
                @else
                    <li class="dropdown">
                        <a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" 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 target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{ url('/logout') }}"><i class="fa fa-btn fa-sign-out"></i>Logout</a></li>
                        </ul>
                    </li>
                @endif

This is the autogenerate code after i run the command : php artisan make:auth After it generate the file and i set up for the database, it can let me to register and login. But it cant show the logout button after i login or register. The code above is checking the session have any user or not. If that is no user login, then it will come out the login and register button on the right of website. Like this:Default of the main page -

Main Page


But everything is remain same, and i could find out what is the wrong part.Auth::check() Auth::user() this two i already try, and it still didnt works. Anyone one have the solution?

Ad

Answer

If this is all default after adding the Auth scaffolding you will have to adjust a route.

You will want to apply the web middleware group to any route that you will be using that layout. You can move them to the Route::group that is using the 'web' middleware.

Route::group(['middleware' => ['web']], function () {
    Route::get('/', function () {
        return view('welcome');
    });        
});

This web group gives you sessions, which Auth is using.

Ad
source: stackoverflow.com
Ad