dqrnskni67375 2016-01-16 09:59
浏览 81
已采纳

Laravel 5.2 - Session ::无法正常工作

I want to display an 'falsh-message' for the user I start to redirect him in the routes.php with following code :

Route::get('/alert',function () {
    return redirect()->route('home')->with('message', 'This is a Test Message!');
});

In the alerts.blade.php that I include in the home view I would like to read this message with:

Route::group(['middleware' => ['web']], function () {
  Route::get('/alert',function () {
        return redirect()->route('home')->with('message', 'This is a Test Message!');
    });
});

My Session would be set under storage\framework\sessions with the following code :

a:5:{s:6:"_token";s:40:"8304u3fjR9EhvA88QMVGQnGcgdUcWoZj9LrHaDPh";s:7:"message";s:23:"This is a Test Message!";s:5:"flash";a:2:{s:3:"new";a:0:{}s:3:"old";a:1:{i:0;s:7:"message";}}s:9:"_previous";a:1:{s:3:"url";s:22:"http://localhost/alert";}s:9:"_sf2_meta";a:3:{s:1:"u";i:1452937821;s:1:"c";i:1452937821;s:1:"l";s:1:"0";}}

But the Problem is that Laravel gives me no output from the message because it is empty. So maybe someone can help me.

routes.php :

Route::group(['middleware' => ['web']], function () {
    Route::get('/', [
        'uses' => '\App\Http\Controllers\HomeController@index',
        'as' => 'home',
    ]);
    Route::get('/alert',function () {
        return redirect()->route('home')->with('message', 'This is a Test Message!');
    });
});
  • 写回答

4条回答 默认 最新

  • dpleylxzx47207117 2016-01-16 15:14
    关注

    Insert session flash data explicitly..

    Route::get('/alert',function () {
        $request->session()->flash('message', 'Task was successful!');
        return redirect()->route('home');
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?