我正在尝试处理我的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
为空。我的重定向有什么问题吗?感谢您的帮助!
blade
模板中检查是否存在一些Session
消息?例如@if(Session::has('foo') {{ $foo }} @endif
。 - TarasovychPostTooLargeException
异常时,会话尚未开始,所以我需要想办法启动会话...\Session::start()
和session_start()
都没有帮助我,但我还没有深入研究这个方向... - lubartSession
没有启动... - Tarasovych