Skip to content

Instantly share code, notes, and snippets.

@jilcimar
Created November 10, 2021 01:26
Show Gist options
  • Save jilcimar/40202cb0139946a3060b9617aea29a83 to your computer and use it in GitHub Desktop.
Save jilcimar/40202cb0139946a3060b9617aea29a83 to your computer and use it in GitHub Desktop.
Laravel Exception Json for API
public function render($request, Throwable $e)
{
if ($request->is('api/*')) { //add Accept: application/json in request
if($e instanceof ValidationException)
return response()->json($e->errors(),$e->status);
}
$retval = parent::render($request, $e);
return $retval;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment