会话变量在laravel中重定向期间不持久
用户身份验证后,我将重定向到homecontroller,并将身份验证令牌设置为会话,以便在home控制器中使用--
I am making a redirect to homecontroller after user authenticates and set a auth token to session for use in the home controller as -
控制器1
$secret = Crypt::encrypt($secret);
Session::put('secret', $secret);
Session::save();
return redirect()->action('loginController@homeRedirect');
控制器2-> homeRedirect
function homeRedirect(){
dd(Session::all());
if(Session::has('secret')){
$secret = Session::get('secret');
Session::forget('secret');
这是转储中的空白数组.会话中没有任何内容,但是,如果我测试了此dd(Session::all())
,它将提供正确的详细信息.
Here the dump comes blank array. nothing comes in the session, however if i test this dd(Session::all())
then it gives correct details.
我也尝试过使用with('secret', $secret)
发送数据,但这也返回了空白会话.
Also I have tried as sending data using with('secret', $secret)
but that is also returning a blank session.
我的session.php文件具有以下条目
'driver' => 'file',
,而laravel版本是5.2.
My session.php file has following entry
'driver' => 'file',
and the laravel version is 5.2.
编辑
如果我这样尝试-
function homeRedirect(Request $request){
$ses = $request->session()->get('secret');
dd($ses);
然后我出现错误,指出Session store not set on request.
Then I get error stating Session store not set on request.
在使用Laravel 5.2时,应确保已在Web中间件中为loginController@homeRedirect
设置了路由.
As you are using Laravel 5.2 , you should make sure you have set route for your loginController@homeRedirect
in web middleware.
您的路线应在routes.php
中进行定义
Your route should be defined in routes.php
like so
Route::group(['middleware' => ['web']], function () {
Route::get('/homeredirect','loginController@homeRedirect');
}
如果是这样定义的:
Route::group(['middleware' => ['web']], function () {
}
Route::get('/homeredirect','loginController@homeRedirect');
它不起作用