Support the ongoing development of Laravel.io →
posted 10 years ago
Requests
Last updated 2 years ago.
0

404 Is usually the right response for a missing resource.

If you want to send back a custom 404 page for that case, you could use Response::make($content, $statusCode) from the docs.

You could create a view and then call $view->render() on it to get the content.

The other way to do it is, instead of calling App::abort(404); you could throw a custom exception (like say, UserNotFoundException) and register your own handler for that exception.

Last updated 2 years ago.
0

Thanks for the response. I understand your proposed solutions. However, the specific challenge for me here is a bit different. I want a custom 404 response, but must really give this response at the specific point in code marked with a comment.

If I don't do this, the closure used in Route::bind will return null, and throw an exception, as the closure in Route::get expects an argument of type User.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2024 Laravel.io - All rights reserved.