Files
prn2026/app/Http/Requests/Admin/Management/StoreRepresentativeRequest.php
2026-06-03 08:51:22 +08:00

44 lines
1.5 KiB
PHP

<?php
namespace App\Http\Requests\Admin\Management;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreRepresentativeRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
protected function prepareForValidation(): void
{
$this->merge([
'ic_number' => blank($this->input('ic_number')) ? null : preg_replace('/\D+/', '', (string) $this->input('ic_number')),
'saluran_mengundi_id' => blank($this->input('saluran_mengundi_id')) ? null : $this->input('saluran_mengundi_id'),
]);
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'type' => ['required', Rule::in(['police', 'kkm', 'jkm'])],
'election_id' => ['required', 'integer', 'exists:elections,id'],
'pusat_mengundi_id' => ['required', 'integer', 'exists:pusat_mengundis,id'],
'saluran_mengundi_id' => ['nullable', 'integer', 'exists:saluran_mengundis,id'],
'name' => ['required', 'string', 'max:255'],
'ic_number' => ['nullable', 'digits:12'],
'phone_number' => ['nullable', 'string', 'max:30'],
'rank' => ['nullable', 'string', 'max:255'],
'station' => ['nullable', 'string', 'max:255'],
'agency' => ['nullable', 'string', 'max:255'],
'notes' => ['nullable', 'string', 'max:2000'],
'note' => ['nullable', 'string', 'max:2000'],
];
}
}