api/app/Http/Requests/UpdateHuntRequest.php

66 lines
1.9 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Validation\Rule;
class UpdateHuntRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'partner_id' => 'sometimes|string',
'title' => 'sometimes|string',
'slug' => [
'sometimes',
'string',
Rule::unique('hunts', 'slug')->ignore($this->route('hunt')),
],
'description' => 'nullable|string',
'status' => 'sometimes|string',
'difficulty' => 'sometimes|string',
'city' => 'sometimes|string',
'latitude' => 'nullable|numeric',
'longitude' => 'nullable|numeric',
'start_radius_m' => 'nullable|integer|min:1',
'is_public' => 'boolean',
'estimated_duration_min' => 'nullable|integer',
'start_at' => 'nullable|date',
'end_at' => 'nullable|date',
'image' => 'nullable|string',
'creator_id' => 'nullable|exists:users,id',
];
}
/**
* Handle a failed validation attempt.
*
* @return void
*
* @throws \Illuminate\Http\Exceptions\HttpResponseException
*/
protected function failedValidation(Validator $validator)
{
throw new HttpResponseException(response()->json([
'message' => 'Validation errors',
'errors' => $validator->errors(),
], 422));
}
}