Auth :: guest () always returns true | Laravel 5.4

0

I'm using the features offered by laravel for authentication, but even if I logged on the auth :: guest () command returns true as if it were a guest.

Follow the code for my middleware

<?php

namespace App\Http\Middleware;

use Closure;
use Auth;

class Autorizacao
{
     /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(!$request->is('/') && !$request->is('home') && !$request->is('login') && !$request->is('logout') && !$request->is('register') && Auth::guest()){
            if(Auth::guest())
                echo 'true';
            else
                echo 'false';
            //return redirect('/login');
        }
        return $next($request);
    }
}

I did not use dd () because it terminates the process to display the result, and may not log in.

In this case I would like the login screen to be displayed if the user was not logged in, but could access the routes for login / logout or home, but if logged in would have access to all the screens.

    
asked by anonymous 14.03.2017 / 15:49

1 answer

0

I've been able to resolve it differently, I stopped using middleware and added it to the constructor of my controllers :

public function __construct(){
    $this->middleware('auth');
}

On each controller.

Thank you for your cooperation.

    
14.03.2017 / 20:41