Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lubart's avatar

Handling PostTooLargeException

Hi! I am trying to handle PostTooLargeException in my Laravel 5.5 application.

When I trying to upload too big file through my form I receive PostTooLargeException which I successfully catch in app\Exceptions\Handler.php, but on that step I would like to redirect user back to the page with form and show an error message.

I wrote following code:

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');
            }
    ...
    }
}

As a result I was redirected to the proper page but without any message and ErrorBag was empty. Did I something wrong with that redirection?

Thank you a help!

0 likes
3 replies
Helmchen's avatar

try to pass an array to withErrors()

->withErrors(["message" => "Size of attached file should be less ".ini_get("upload_max_filesize")."B"]);
lubart's avatar

Thank you for answer, but it also does not work, the ViewErrorBag is still empty

Please or to participate in this conversation.