38 lines
1.0 KiB
PHP
38 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Api\V1;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
final class SyncVolunteerAvailabilityRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
public function rules(): array
|
|
{
|
|
$event = $this->route('event');
|
|
$eventIds = [$event->id];
|
|
if ($event->parent_event_id) {
|
|
$eventIds[] = $event->parent_event_id;
|
|
} elseif ($event->isFestival()) {
|
|
$eventIds = array_merge($eventIds, $event->children()->pluck('id')->all());
|
|
}
|
|
|
|
return [
|
|
'availabilities' => ['required', 'array'],
|
|
'availabilities.*.time_slot_id' => [
|
|
'required', 'ulid',
|
|
Rule::exists('time_slots', 'id')->whereIn('event_id', $eventIds),
|
|
],
|
|
'availabilities.*.preference_level' => ['sometimes', 'integer', 'min:1', 'max:5'],
|
|
];
|
|
}
|
|
}
|