Call to a member function setCookie () on null

1

Good afternoon, I am using Laravel 5.6 and I have just applied middleware to my routes, it does the filtering in the following way:

public function handle($request, Closure $next)
{
    $tipoUsuario=$this->auth->user()->id_role;

    if ($tipoUsuario!=1) {
        return view('denied');
        }
    return $next($request); 

}

But the system responds with the error:

  

Call to a member function setCookie () on null

    
asked by ALVARO ROBERTO BACARREZA ARZAB 17.05.2018 в 19:59
source

1 answer

1

The Middleware file has no scope for resources.

I recommend you declare a route in the file routes/web.php :

Route::get('/denied', ['as' => 'denied', function() {
    return view('denied');
}]);

And in the file Middleware something like the following:

public function handle($request, Closure $next)
{
    $tipoUsuario = $this->auth->user()->id_role;

    if ($tipoUsuario != 1) {
        return redirect()->route('denied');
    }

    return $next($request); 
}
    
answered by 31.08.2018 в 23:25