1To do that, we need to add this logic to the app/Exceptions/Handler.php class:
2
3use Illuminate\Database\Eloquent\ModelNotFoundException;
4
5// ...
6
7public function render($request, Exception $exception)
8{
9 if ($exception instanceof ModelNotFoundException && $request->wantsJson()) {
10 return response()->json(['message' => 'Not Found!'], 404);
11 }
12
13 return parent::render($request, $exception);
14}