Last active
January 20, 2021 21:35
-
-
Save xxRockOnxx/329c35b93ea9821a1b255ab36c1fee98 to your computer and use it in GitHub Desktop.
[Laravel] Convert dot array validation error to nested array
This file contains 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
<?php | |
namespace App\Exceptions; | |
class Handler | |
{ | |
/** | |
* Convert a validation exception into a JSON response. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Illuminate\Validation\ValidationException $exception | |
* @return \Illuminate\Http\JsonResponse | |
*/ | |
protected function invalidJson($request, ValidationException $exception) | |
{ | |
$errors = []; | |
foreach ($exception->errors() as $key => $value) { | |
array_set($errors, $key, $value); | |
} | |
return response()->json($errors, $exception->status); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment