【发布时间】:2018-04-09 18:18:31
【问题描述】:
我正在尝试在我的 Laravel 5.5 应用程序中处理 PostTooLargeException。
当我尝试通过我的表单上传太大的文件时,我收到了PostTooLargeException,我在app\Exceptions\Handler.php 中成功捕获了它,但在这一步我想将用户重定向回带有表单的页面并显示错误消息。
我写了以下代码:
class Handler extends ExceptionHandler
{
...
public function render($request, Exception $exception)
{
...
if($exception instanceof PostTooLargeException){
return redirect()->back()->withErrors("Size of attached file should be less ".ini_get("upload_max_filesize")."B", 'addNote');
}
...
}
}
结果我被重定向到正确的页面,但没有任何消息,ViewErrorBag 是空的。
我的重定向有什么问题吗?
谢谢你的帮助!
【问题讨论】:
-
如果有一些
Session消息,你会检查你的blade吗?喜欢@if(Session::has('foo') {{ $foo }} @endif -
@Tarasovych 是的,我有,而且我没有任何会话消息。现在我明白了,在出现
PostTooLargeException的那一刻,会话还没有开始,所以我需要以某种方式开始一个会话......\Session::start()和session_start()没有帮助我,但我没有深入挖掘还是那样…… -
嗯,很奇怪
Session还没开始...
标签: php redirect handler laravel-5.5