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

前端 未结 16 2700
长情又很酷
长情又很酷 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

    In your view:

    @foreach (['danger', 'warning', 'success', 'info'] as $msg) @if(Session::has('alert-' . $msg))

    {{ Session::get('alert-' . $msg) }}

    @endif @endforeach

    Then set a flash message in the controller:

    Session::flash('alert-danger', 'danger');
    Session::flash('alert-warning', 'warning');
    Session::flash('alert-success', 'success');
    Session::flash('alert-info', 'info');
    

提交回复
热议问题