I made a custom route middleware to check if my user has enough privileges to see a page, when user doesn't have enough privileges I get the following error message:
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to a member function setCookie() on null
This is my controller:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Auth;
class AuthAdmin
{
public function handle($request, Closure $next)
{
$user = Auth::user();
if($user && $user['privileges'] > 2){
return $next($request);
}
return view('auth.login');
}
}
Any idea what's wrong with my code?