Laravel 4 how to display flash message in view?

后端 未结 11 1002
粉色の甜心
粉色の甜心 2021-02-04 00:33

I\'m trying to get my flash message to display.

This is in my routing file

Route::post(\'users/groups/save\', function(){

return Redirect::to(\'users/g         


        
11条回答
  •  离开以前
    2021-02-04 01:13

    Laravel 4.2 Personally i use

    Session::flash('key', 'value');
    return Redirect::to('some/url');
    

    then in the view id first check if there is a session of that key in the view

    @if(Session::has('key'))
       {{Session::get('key')}} //this prints out the message or your 'value' in the session::flash method
    @endif
    

    it works for me most of the time and i usually have that blade template integrated into my view just so i can push success messages to the view from my codes.

    please do note that it is stated in the documentation that "Sometimes you may wish to store items in the session only for the next request. You may do so using the Session::flash method" so yes it expires after the next page.

    hope this helps

提交回复
热议问题