Support the ongoing development of →
posted 10 years ago
Last updated 2 years ago.

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.

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.

Sign in to participate in this thread!


Your banner here too?


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

Your logo here?

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

© 2024 - All rights reserved.