Skip to main content

404 page: Accept application/json and Override Error Message

Premium
4:32

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 09 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

F
Fcmarquis ✓ Link copied!

Thanks for this tutorial. Would it be ok to add this to api routes 404 errors only? Keeping regular http 404 errors to default 404 web page

public function register() { $this->renderable(function (NotFoundHttpException $e) { if ( request()->is('api/*') ) { return response()->json([ 'message' => 'Object not found' ], 404); } }); }

PK
Povilas Korop ✓ Link copied!

Yes, that's one way of doing it. Another way is request()->expectsJson(), from what I remember

V
Velkacem ✓ Link copied!

Thanks for this tutotrial!

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.