Support the ongoing development of Laravel.io →
posted 10 years ago
Requests

i cant seem to find a good way to handle missing routes in Laravel5 . in laravel 4 we could use APP::missing on routes.php i have tried re-enabling routes.php and trying app::missing but it doesn't work anymore.

this is what GrahamCampbell said. "You can catch exceptions in the kernel class if you want?"

and doing this works.

public function handle($request)
{
    try
    {
        return parent::handle($request);
    }
    catch (Exception $e)
    {
        echo \View::make('index');
        exit;
        // throw $e;
    }
}

but i am not sure if this is the best way to do it. and even he agrees.

any suggestion/idea will be greatly appreciated, for now i am using the above code to handle http error in App\Http\Kernel

Last updated 2 years ago.
0

More detailed on StackOverflow.

Open up app\Http\Kernel.php and change the content in the handle method to this:

try
{
	return parent::handle($request);
}
catch(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e)
{
	return $this->app->make('Illuminate\Routing\ResponseFactory')->view('error.404', [], 404);
}
catch (Exception $e)
{
	throw $e;
}

This will catch 404 Not Found exceptions and display the view file error/404.blade.php.

I believe this is the way in Laravel 5 to catch exceptions.

Last updated 2 years ago.
0

@Marwelln thanks

yes that's a better way to handle this then what i did, what i did basically redirect any page errors not just 404 to index. this way at-least it will let us control which page to deploy for each types of errors.

i am gonna use this for now, i am assuming even this will change in few days hehe.

Last updated 2 years ago.
0

This doesn't work for me. Just a blank page.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

muhamin muhamin Joined 9 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.