会话无法通过异常处理程序进行 [英] Session does not work from Exception Handler
本文介绍了会话无法通过异常处理程序进行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当引发某些异常但我无法访问从异常处理程序刷新的消息时,我需要使用Flash消息将用户重定向到带有闪烁消息的主页.这是我的代码:
I need redirect user to the homepage with a flash message when some exception are throw but I can't access message flashed from Exception handler. This is my code :
if(config('app.env') == 'production')
{
if($exception instanceof FatalErrorException ||
$exception instanceof FatalThrowableError
){
return redirect(route('home'))->with('message',
[
'type' => 'info',
'content' => 'Nous nous excusons pour cette gène !
Notre équipe technique est informée du problème et passera
à la correction dans le plus brefs délais que possible
'
]);
}
}
return parent::render($request, $exception);
}
出什么问题了?
我访问闪烁的消息是这样的:
I access the flashed message like this :
@if(session()->has('message'))
<div data-toggle="alert-dismissable" role="alert" class="alert alert-{{ session('message')['type'] ?? 'success' }}">
<i class="fa fa-{{ session('message')['type'] ?? 'success' }}"></i>
{{ session('message')['content'] ?? session('message') }}
</div>
@endif
推荐答案
您必须使用 session()
而不是 with
,您可以在会话中使用此值:
You have to user session()
instead of with
the value in session you can do this with:
if(config('app.env') == 'production')
{
if($exception instanceof FatalErrorException ||
$exception instanceof FatalThrowableError
){
session()->flash('message', [
'type' => 'info',
'content' => 'Nous nous excusons pour cette gène !
Notre équipe technique est informée du problème et passera
à la correction dans le plus brefs délais que possible
'
]);
return redirect(route('home'));
}
}
return parent::render($request, $exception);
}
如果要使用 with()
,则必须更改视图
if you want to use with()
then you have to change your view
@if(isset($message))
<div data-toggle="alert-dismissable" role="alert" class="alert alert-{{ $message['type'] ?? 'success' }}">
<i class="fa fa-{{ $message['type'] ?? 'success' }}"></i>
{{ $message['content'] ?? $message['content'] }}
</div>
@endif
希望这会有所帮助
这篇关于会话无法通过异常处理程序进行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文