36 lines
		
	
	
		
			879 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			879 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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));
 | 
						|
    }
 | 
						|
}
 |