[英]Laravel 5.5: Sessions not working
I'm using Session::put('client', $id);
我正在使用
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. 设置会话值,该值将持续存在于控制器内以及应用程序内的其他位置,但我通过Vue通过API路由调用的控制器除外。
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. 此后,我对“ session.php”文件进行了编辑:
'driver' => env('SESSION_DRIVER', 'database')
,并使用php artisan session:table
创建了“ sessions”表,不管我做什么来创建其他会话变量,它都改变了一切,表本身没有任何改变。
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. 我试过了:
$request->session()->get('client')
, session('client')
和: Session::get('client')
从控制器内部,首先触发错误(请阅读下一段),或不返回任何内容。
I've tried: Session::put('client', $id); Session::save();
我试过了:
Session::put('client', $id); Session::save();
Session::put('client', $id); Session::save();
which also didn't do anything. 这也什么也没做。
I've tried: print_r( $request->session()->all() );
我试过了:
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? 有任何想法吗?
Based on an answer elsewhere , I had to change the $middlewareGroups
variable to: 根据其他答案 ,我不得不将
$middlewareGroups
变量更改为:
'api' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Session\Middleware\StartSession::class,
'throttle:60,1',
'bindings',
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.