Help, help! laravel5.4 prints Auth::check(); in the constructor of the class and returns false, and prints it in the method of the class and returns true. Make sure you are logged in
Pictured:
returns false
高洛峰2017-05-16 13:00:35
This problem has existed since Laravel 5.3 started grouping routes. The reason is that the middleware is not running when construct is run.
use Closure;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $user;
public function __construct(Request $request)
{
$this->middleware(function($request,Closure $next){
$this->user = Auth::user();
return $next($request);
});
}
}
迷茫2017-05-16 13:00:35
function __construct(Request $request)
{
$this->middleware(function ($request, $next) {
dd(Auth::check());
});
}