Laravel global middleware can't get session

前端 未结 2 1941
梦毁少年i
梦毁少年i 2021-01-19 20:06
 protected $middleware = [
     \\App\\Http\\Middleware\\Syspoint::class,
]

use Session;
class Syspoint
{
    echo \\Session::get(\'syspoint\');
}

2条回答
  •  盖世英雄少女心
    2021-01-19 20:40

    You are calling Session but it is not already started.

    If you need Session inside your middleware you have to put it in the property protected $middlewareGroups under the key web and after the call to StartSession, i.e.:

     protected $middlewareGroups
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \App\Http\Middleware\Syspoint::class,
    

提交回复
热议问题