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

kenmaclord's avatar

Exception Handler and Session

Hello,

I would like to catch a PostTooLargeException in the render method of Handler.php file. so I did :

public function render($request, Exception $exception)
{
    if ($exception instanceof PostTooLargeException) {
        return redirect('mypage')->with('toobig', "File too big. 30Mo max.");
    }

    return parent::render($request, $exception);
}

But in my view, nothing is in the session.

I tried to manually throw a ValidationException, but, in the view, the $errors variable is empty too.

throw ValidationException::withMessages([
    'file' => ["File too big. 30Mo max."],
]);

thanks!

Anyone has an idea?

(Laravel 5.8.10)

0 likes
2 replies
kenmaclord's avatar

Thanks perfect!

sorry not finding the post in the discussions, I did a wrong search (search on lessons...)

Please or to participate in this conversation.