xxxxxxxxxx
use Illuminate\Support\Facades\Validator;
$validator = Validator::make($request->all(), [
'photos.profile' => 'required|image',
]);
xxxxxxxxxx
public function failedValidation(Validator $validator)
{
throw new HttpResponseException(response()->json([
'success' => false,
'message' => 'Validation errors',
'data' => $validator->errors()
]));
}
xxxxxxxxxx
use Illuminate\Http\Response;
protected function failedValidation(\Illuminate\Contracts\Validation\Validator $validator)
{
$response = new Response(['error' => $validator->errors()->first()], 422);
throw new ValidationException($validator, $response);
}
xxxxxxxxxx
public function response(array $errors)
{
// Always return JSON.
return response()->json($errors, 422);
}