Laravel 5.5:会话无法正常工作 [英] Laravel 5.5: Sessions not working

查看:37
本文介绍了Laravel 5.5:会话无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Session :: put('client',$ id); 设置一个会话值,该值将持续存在于控制器内以及应用程序内的其他地方,除了我正在通过Vue通过API路由调用控制器.

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.

此后,我进行了修改:'driver'=>env('SESSION_DRIVER','database')到"session.php"文件,并使用 php artisan session:table 创建"sessions"表,这些表都没有更改了任何内容,表本身没有任何内容,无论我如何创建其他会话变量.

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.

我尝试过: $ request-> session()-> get('client') session('client')和:<控制器中的code> Session :: get('client'),它首先会触发错误(请阅读下一段),或者什么都不返回.

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.

我尝试过: Session :: put('client',$ id);Session :: save(); 也不执行任何操作.

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

我已经尝试过: print_r($ request-> session()-> all()); 从控制器内部,但是出现了错误:

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.

有什么想法吗?

推荐答案

基于其他地方的答案,我不得不将 $ middlewareGroups 变量更改为:

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',
],

这篇关于Laravel 5.5:会话无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆