Auth::user() returns null in Laravel 5.2

前端 未结 4 799

I have searched and found various results like these: auth()->user() is null in Laravel 5.2 and Auth::user() returns null

But, mine is still not working.

4条回答
  •  独厮守ぢ
    2021-01-06 10:50

    I had a similar problem. I was defining a custom Middleware for the API group and Auth was always appearing as null.

    I fixed this by loading in the EncryptCookies Middleware before my custom one.

    'api' => [
        \App\Http\Middleware\EncryptCookies::class,
        \App\Http\Middleware\VerifyParametersMiddleware::class, // your custom middleware, load after EncryptCookies
        'throttle:60,1',
        'bindings',
    ],
    

    This change can be made within Kernel.php.

提交回复
热议问题