duan0414 2019-06-02 13:56
浏览 161

重定向后,Laravel会话/闪存变量不会保留

So I'm trying to redirect with a session/flash variable, but I can't seem to figure out why the session variable is never present after the redirect.

I have a controller action like this:

public function verifyAction(Request $request)
{
    return redirect()
        ->route('login')
        ->with('test', 'Test');
}

and on the login route I'm dumping the session (using Laravel's Session()->all() function), however it never seems to contain the 'test' key.

I'm using 'artisan route:list' to show the routes like this:

+--------+----------+--------+--------+---------------+------------+
| Domain | Method   | URI    | Name   | Action        | Middleware |
+--------+----------+--------+--------+---------------+------------+
|        | GET|HEAD | login  | login  | @loginAction  | web        |
|        | GET|HEAD | verify | verify | @verifyAction | web        |
+--------+----------+--------+--------+---------------+------------+

and both routes are using the web middleware as specified in the docs ([laravel.com/docs][1]) but the session data is always empty after the redirect, like this:

["_flash"]=>
array(2) {
    ["old"] => array(0) {}
    ["new"] => array(0) {}
}

I'm expecting to see the 'test' key in the _flash array after the redirect but actually it's always empty. Any ideas what's going on here and how I could get it working?

One thing that strikes me as strange is that I can add normal session variables in the controller like this and it works fine:

Session::put([
    'test-2' => 'Testing'
]);

So session variables work fine, it's just flash variables that aren't working.

Distro: Ubuntu 19.04 (Disco Dingo), Laravel 5.8, Laradock, Docker version 18.09.5, build e8ff056, Php 7.2.15.

EDITS

Browser activity:

Request URL: http://localhost/verify?code=ABC&uid=2 Request Method: GET Status Code: 302 Found Remote Address: [::1]:80 Referrer Policy: no-referrer-when-downgrade

Request URL: http://localhost/login Request Method: GET Status Code: 200 OK Remote Address: [::1]:80 Referrer Policy: no-referrer-when-downgrade

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思