Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...