rrafia's avatar

Custom view not found excpetion in Laravel

Is there a way to capture the view not found exception (not the http route not found) in Laravel 5.2 and display a custom error? I tried to capture InvalidArgumentException in app/Exceptions/handler and return a simple message with no luck.

Thank you in advance

0 likes
3 replies
bobbybouwmann's avatar

You can do something like this

public function render($request, Exception $e)
{
    if ($e instanceof \InvalidArgumentException) {
        dd($e->getMessage());
    }
    
    if ($e instanceof NotFoundHttpException) {
        return redirect()->route('dashboard', subDomain());
    }

    return parent::render($request, $e);
}
1 like
rrafia's avatar

Still not working. When I go to a view that doesn't exist, I still get the Laravel "ErrorException in FileViewFinder.php line 137 ...view not found...." I would like to show something else when a view does not exists.

Please or to participate in this conversation.