Laravel 5.5: Sessions not working

[亡魂溺海] 提交于 2020-06-01 04:18:40

问题


I'm using Session::put('client', $id); to set a session value, which is persisting within the controller and elsewhere within the application, with the exception of a controller I'm calling via the API route via Vue.

I've since made the edit: 'driver' => env('SESSION_DRIVER', 'database') to the "session.php" file, and used the php artisan session:table to create the "sessions" table, none of which has changed anything, and there's nothing in the table itself, regardless of what I do to create additional session variables.

I've tried: $request->session()->get('client'), session('client'), and: Session::get('client') from within the controller, which in the first instance triggers an error (read the next paragraph), or returns nothing.

I've tried: Session::put('client', $id); Session::save(); which also didn't do anything.

I've tried: print_r( $request->session()->all() ); from within the controller, but got an error:

"Session store not set on request."

I am declaring the "Session" above the parent class of the method.

Any ideas?


回答1:


Based on an answer elsewhere, I had to change the $middlewareGroups variable to:

'api' => [
    \App\Http\Middleware\EncryptCookies::class,
    \Illuminate\Session\Middleware\StartSession::class,
    'throttle:60,1',
    'bindings',
],


来源:https://stackoverflow.com/questions/48399875/laravel-5-5-sessions-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!