Laravel Session套餐(laravel外部)会话数据不会跨越路线
index.php代码:
$manager = new StartSession($app['session']);
$response = $manager->handle(
$app['request'],
function(Illuminate\Http\Request $request){
return Route::dispatchToRoute($request);
}
);
$manager->terminate();
$response->send();
路线档案:
Route::get('auth', function() {
Session::put('Maxhunter', 'this is my name');
dd(Session::all()); // output
// array:2 [▼ "_token" => "7UM4Q61zR3WNGPIMFQ8Rmo7dqtdJY69lSmzkN2s0"
// "Maxhunter" => "this is my name" ]
Route::get('user', array('before' => 'old', function() {
dd(Session::all()); // output
// array:1 [▼"_token" => "gZ04sr3ymH0gclkcIY9bg0ZhowWj3lFkOnfW7a9v"]
答案 0 :(得分:0)
要使会话正常工作,您必须将路由放在Web中间件组中。
在routes.php
文件中:
Route::group(['middleware' => ['web']], function () {
// Your routes go here
});