首页 > 解决方案 > 在 PostTooLargeException laravel 5.6 之后尝试重定向到上一个视图(有错误)

问题描述

**(Laravel 5.6)**在提交带有文件输入的表单后,laravel 抛出 PostTooLargeException,我想重定向回上传视图并显示错误消息。我发现我可以在 Handler.php 方法 render() 中重定向回:

`if ($exception instanceof \Illuminate\Http\Exceptions\PostTooLargeException)
        {
            return redirect()->back();
        }
`

但我想重定向错误,这些错误将显示在上传表单视图中。我已经尝试了下面链接中的所有解决方案,但没有任何效果。

Laravel 重定向返回 with() 消息

感谢帮助。

这是异常的图像:PostTooLargeException

标签: laravellaravel-5.6

解决方案


尝试增加 php.ini 文件中的“post_max_size”以避免该异常

对于错误,这应该有效

redirect()->back()->withErrors();

这是一个链接,可以帮助您解决看不到错误的原因。https://laracasts.com/discuss/channels/code-review/redirect-with-errors-not-working?page=1


推荐阅读