Sending 404 error code in Laravel or Lumen

In this post, I am going to show you how to send 404 error response code in Lumen or Laravel 5.5

Sending 404 response in JSON format

if(!Post::find($id))
 return response()->json(['msg'=>'Sorry,Page you are looking for does not exist'], 404);
else
//do stuff

Generating 404 exceptions in Laravel 5.5

if(!Post::find($id))
abort(404);
else
//do stuff

One thought to “Sending 404 error code in Laravel or Lumen”

Leave a Reply

Your email address will not be published. Required fields are marked *