0

**(Laravel 5.6)**After submitting form with file input, laravel throws PostTooLargeException, I want to redirect back to upload view with error message. I found that I can redirect back in Handler.php method render() with:

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

But I want to redirect with errors which will be shown in upload form view. I have tried all solutions at link below but nothing worked.

Laravel redirect back with() message

Thanks for help.

Here is image of exception:PostTooLargeException

Denis2310
  • 939
  • 1
  • 15
  • 41
  • I have found the solution here: https://stackoverflow.com/questions/49650234/handling-posttoolargeexception-in-laravel-5-5 – Denis2310 Jun 05 '18 at 17:56

1 Answers1

0

Try increasing the 'post_max_size' in your php.ini file to avoid that exception

For the errors this should work

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

Here's a link that may help you trouble shoot why you are not seeing the errors. https://laracasts.com/discuss/channels/code-review/redirect-with-errors-not-working?page=1

relytmcd
  • 234
  • 1
  • 9
  • I have $errors message bag in upload view which is showing errors if validation fails (image upload), but in that one specific case where I try to upload some shortcut from desktop to test my validation rules, then that file is uploading for at least 30 seconds and then throws that exception. All errors are shown if validation fails but in that case when I want to redirect back withErrors() then it wont show anything. – Denis2310 Jun 05 '18 at 17:42