Laravel 5.2 flash消息无法正常工作

时间:2016-05-28 11:42:20

标签: php laravel laravel-5.2

我正在使用使用Flash; 来显示我的Flash消息,但它们没有显示

protected function store(Request $request)
{

   $this->validate($request, [
        'service_name' => 'required'
    ]);

    $service = new Service();
    $service->service_name = $request->input('service_name');
    $service->business_id = Auth::user()->user_id;
    $service->save();

    Flash::message('Service successfully added');

    return redirect('/business/editservices');
    }

查看代码

@if (Session::has('flash_notification.message'))
 <div class="alert alert-{{ Session::get('flash_notification.level') }}">
 <button type="button" class="close" data-dismiss="alert"   aria-hidden="true">&times;</button>
   {{ Session::get('flash_notification.message') }}
</div>
  @endif

可能是什么问题?请帮忙

2 个答案:

答案 0 :(得分:2)

如果你有一个请求对象,只需用它来闪存:

protected function store(Request $request)
{

$this->validate($request, [
    'service_name' => 'required'
]);

$service = new Service();
$service->service_name = $request->input('service_name');
$service->business_id = Auth::user()->user_id;
$service->save();

$request->session()->flash('message', 'Service successfully added');

return redirect('/business/editservices');
}

甚至是使用重定向的人:

return redirect('/business/editservices')->with('message', 'Service successfully added');

然后:

Session::has('message');

答案 1 :(得分:0)

试试这个,它为我工作:

Session::flash('message', 'Your Message');

@if (Session::has('message'))
<div>{!! Session::get('message')!!}</div>
@endif