Laravel 5.8 重定向错误,未显示消息

Laravel 5.8 redirect with error not showing message

我正在使用 Laravel 5.8 和自定义身份验证,因此,我需要使用 缓存标签 。 为了让它工作,我的 CACHE_DRIVE 设置为 array.

但是使用此配置,我无法在重定向到视图时使 Flash 会话消息起作用。

在 CustomAuthController.php 我试过:

return redirect()
       ->route('login')
       ->withErrors('The credentials do not match our records');

OR

return redirect()->route('login')->with('error','The credentials do not match our records');

在 login.blade.php 中结果相同:

<?php print '<pre>'; print_r(session()->all()); ?>

结果:

Array
(
    [_token] => yyUtSaFx3AxPrJR0biJ5HmjyHU0r5PYY0xi4kLGK
    [_previous] => Array
        (
            [url] => http://127.0.0.1:8001
        )
    [_flash] => Array (
            [old] => Array()
            [new] => Array()
        )
)

路线:

Route::group(['middleware' => ['web']], function () {

    // Authentication Routes...
    Route::get('/', 'Auth\CustomAuthController@showLoginForm');

    Route::name('login')->get('login', 'Auth\CustomAuthController@showLoginForm');
    Route::name('login')->post('login', 'Auth\CustomAuthController@login');
    Route::name('logout')->get('logout', 'Auth\CustomAuthController@logout');

    Route::group(['middleware' => ['auth']], function () {
        Route::name('home')->any('home', 'HomeController@home');
    });
});

有人可以帮忙吗? 提前致谢!

尝试:

return redirect()->route('login')->with(['error' => 'The credentials do not match our records']);

请尝试-

CustomAuthController.php:

return redirect()->route('login')->withErrors(['error' => 'The credentials do not match our records']);

login.blade.php:

<p>{{session('errors')->first('error');}}</p>