我正在使用 Laravel 7.12.0,我的 flash 会话数据似乎根本无法使用
request()->session()->flash('status', 'Task was successful!');
或者
return redirect()->route('home')->with('status', "Task was successful");
我正在使用 Debugbar 以及 dd'ing 页面来检查会话数据。
我也知道正在使用网络中间件。
session()->put()
仍然有效,所以我知道将数据放入会话并没有完全损坏,但闪存数据似乎根本不起作用。这是一个全新的安装,所以我正在努力看看可能出了什么问题?
网页.php
Auth::routes();
Route::get('/', 'HomeController@index')->name('home');
Route::group(['middleware' => ['auth']], function () {
Route::resource('polls', 'PollController');
Route::post('polls/vote', 'PollController@vote')->name('polls.vote');
});
Route::resource('api/polls', 'API\PollController');
部分RouteServiceProvider.php
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
kernel.php 中的 Web 中间件组
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
家庭控制器.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
public function index()
{
dd(request()->session()->all());
}
}
重定向后来自我的 HomeController@index 的会话中的内容。
"_token" => "pbZJgfC6XNG2eTqlcGADm68NqhjOHI16rWe4U1bt"
"_previous" => array:1 [▼
"url" => "http://127.0.0.1:8000"
]
"_flash" => array:2 [▼
"old" => []
"new" => []
]
"url" => []
"login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d" => 1
]
谢谢