In Laravel, the best way to pass different types of flash messages in the session

前端 未结 16 2762
长情又很酷
长情又很酷 2020-12-12 09:51

I\'m making my first app in Laravel and am trying to get my head around the session flash messages. As far as I\'m aware in my controller action I can set a flash message ei

16条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 10:34

    Simply return with the 'flag' that you want to be treated without using any additional user function. The Controller:

    return \Redirect::back()->withSuccess( 'Message you want show in View' );
    

    Notice that I used the 'Success' flag.

    The View:

    @if( Session::has( 'success' ))
         {{ Session::get( 'success' ) }}
    @elseif( Session::has( 'warning' ))
         {{ Session::get( 'warning' ) }} 
    @endif
    

    Yes, it really works!

提交回复
热议问题