Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel routing and 404 error

I want to specify that if anything entered in the url address other than existing routes (in routes.php, then show 404 page.

I know about this:

App::abort(404);

but how can I specify the part where everything else except the routes defined?

like image 472
spacemonkey Avatar asked Dec 09 '13 15:12

spacemonkey


People also ask

How do I fix error 404 in laravel?

The fix was to rename parameters. Laravel doesn't accept minus character - . Rather than that you have to use camelCase or underscore ( _ ) variable naming conventions.

Why am I receiving a 404 not found when I try to access a route other than?

Error 404 not found is one of the most common issues you may encounter while browsing. This HTTP status code means the requested page can't be found on the website server. It may indicate a flaw with a hosting service or your domain name system (DNS) configuration settings.

How do I fix 404 Not Found in laravel 9?

It should be enough to just run php artisan vendor:publish --tag=laravel-errors and then edit the newly created resources/views/errors/404. blade.


1 Answers

You can add this to your filters.php file:

App::missing(function($exception)
{
    return Response::view('errors.missing', array(), 404);
});

And create the errors.missing view file to show them the error.

Also take a look at the Errors & Logging docs

EDIT

If you need to pass data to that view, the second parameter is an array you can use:

App::missing(function($exception)
{
    return Response::view('errors.missing', array('url' => Request::url()), 404);
});
like image 162
Antonio Carlos Ribeiro Avatar answered Sep 20 '22 05:09

Antonio Carlos Ribeiro