taktik - laravel
This commit is contained in:
35
app/Http/Requests/InvalidDataResponseTrait.php
Normal file
35
app/Http/Requests/InvalidDataResponseTrait.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use OpenApi\Annotations as OA;
|
||||
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="ValidationError",
|
||||
* type="object",
|
||||
* @OA\Property(property="message", type="string", example="The given data was invalid."),
|
||||
* @OA\Property(
|
||||
* property="errors",
|
||||
* type="object",
|
||||
* @OA\AdditionalProperties(
|
||||
* type="array",
|
||||
* @OA\Items(type="string", example="The title field is required.")
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
trait InvalidDataResponseTrait
|
||||
{
|
||||
protected function failedValidation(Validator $validator): void
|
||||
{
|
||||
throw new HttpResponseException(response()->json([
|
||||
'message' => 'Invalid data.',
|
||||
'errors' => $validator->errors(),
|
||||
], 422));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user