Created
November 10, 2021 01:26
-
-
Save jilcimar/40202cb0139946a3060b9617aea29a83 to your computer and use it in GitHub Desktop.
Laravel Exception Json for API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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