first
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpsertElectionSettingsRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasRole('Admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'registration_start_date' => ['required', 'date'],
|
||||
'registration_end_date' => ['required', 'date', 'after_or_equal:registration_start_date'],
|
||||
'polling_date' => ['required', 'date', 'after_or_equal:registration_end_date'],
|
||||
'is_attendance_active' => ['required', 'boolean'],
|
||||
'is_registration_open_override' => ['nullable', 'in:,0,1'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'is_attendance_active' => $this->boolean('is_attendance_active'),
|
||||
'is_registration_open_override' => $this->resolveOverride(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function resolveOverride(): ?bool
|
||||
{
|
||||
$value = $this->input('is_registration_open_override');
|
||||
|
||||
if ($value === '' || $value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user