获取flash消息的密钥

时间:2016-09-28 08:18:48

标签: php laravel

我和Laravel一起工作,我是新人。我使用以下代码行设置了一条flash消息:session()->flash('status', 'This is my flash message to display');

要检索我使用session('status')的消息。

现在我的问题是,有没有可能获得flash消息的密钥?在我的示例中,flash消息的键是status

3 个答案:

答案 0 :(得分:1)

您可以使用以下方法获取新闪烁值的所有键的数组:

session('_flash.new');

答案 1 :(得分:1)

传递这样的信息

return redirect()->back()->with('success', 'Destination deleted successfully');

像这样使用

@if(Session::has('success'))
  <div class="alert alert-success alert-dismissable alert-box">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    {{ Session::get('success') }}               
  </div>
@endif
@if(Session::has('error'))
  <div class="alert alert-danger alert-dismissable alert-box">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    {{ Session::get('error') }} 
  </div>
@endif 

答案 2 :(得分:1)

在会话中使用类型和消息设置数据数组。

session()->flash('message', [
    'type' => 'success', 
    'body' => 'This is my flash message to display'
]);

然后您可以访问类似

的消息类型
session('message.type')

在您的刀片视图中,您可以执行此操作以获得动态警报消息

@if (session()->has('message'))
    <div class="alert alert-{{ session('message.type') }}">
        {{ session('message.body') }}
    </div>
@endif