且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

$ request->会话在Laravel 5.3资源控制器中不起作用

更新时间:2023-02-19 17:59:22

5.3中,中间件尚未在constructor中运行,因此您无法收集session数据.但是,使用基于闭包的方法,您应该可以通过以下方式访问它:

In 5.3 the middleware hasn't run yet in the constructor, so you're unable to gather session data. But using your closure-based approach, you should be able to access it with something like this:

$this->middleware(function($request, $next) {
    // Get the session value (uses global helper)
    $this->token = session('_admin_id');

    // If the value is null, abort the request
    if (null === $this->token) abort(404);

    return $next($request);
});