60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
|
class StoreHuntRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true; // Authorized by default, or check permission if needed
|
|
}
|
|
|
|
/**
|
|
* 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' => 'nullable|string',
|
|
'title' => 'required|string',
|
|
'slug' => 'required|string|unique:hunts,slug',
|
|
'description' => 'nullable|string',
|
|
'status' => 'required|string',
|
|
'difficulty' => 'required|string',
|
|
'city' => 'required|string',
|
|
'latitude' => 'nullable|numeric',
|
|
'longitude' => 'nullable|numeric',
|
|
'is_public' => 'boolean',
|
|
'estimated_duration_min' => 'nullable|integer',
|
|
'start_at' => 'nullable|date',
|
|
'end_at' => 'nullable|date',
|
|
'image' => 'nullable|string',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Handle a failed validation attempt.
|
|
*
|
|
* @param \Illuminate\Contracts\Validation\Validator $validator
|
|
* @return void
|
|
*
|
|
* @throws \Illuminate\Http\Exceptions\HttpResponseException
|
|
*/
|
|
protected function failedValidation(Validator $validator)
|
|
{
|
|
throw new HttpResponseException(response()->json([
|
|
'message' => 'Validation errors',
|
|
'errors' => $validator->errors()
|
|
], 422));
|
|
}
|
|
}
|