// In Laravel 9
// Update register() in App/Exceptions/Handler.php
use SymfonyComponentHttpKernelExceptionNotFoundHttpException;
public function register()
{
$this->renderable(function (NotFoundHttpException $e, $request) {
if ($request->is('api/*')) {
return response()->json([
'message' => 'Not found.'
], 404);
}
});
}