stevemo's avatar

Redirect after NotFoundHttpException with Lumen

I am trying to redirect to the home page after a NotFoundHttpException '404'. using Lumen. I have try to send a redirect from App\Exceptions\Handler in the render method but I only get a white page with status of 500? Any idea how to achieve this?

0 likes
3 replies
bobbybouwmann's avatar

You need to update the App\Exceptions\Handler file and do this in the render method

public function render($request, Exception $e)
{
    if ($e instanceof NotFoundHttpException) 
    {
        return Redirect::home(); // Or do here what ever you want
    }

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

Make sure you import the class at well at the top of this file

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2 likes
stevemo's avatar
stevemo
OP
Best Answer
Level 1

I was doing exactly like @bobbybouwmann but using redirect('/') helper instead of the facade. Anyway the problem was the session driver in the .env was set to memcached and I don't have it installed. Change the setting to file driver and it work!

Thanks Guys!

Please or to participate in this conversation.