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

41 lines
1.1 KiB
PHP

<?php
namespace App\Http\Requests\Admin\Setup;
use App\Models\PusatMengundi;
use App\Models\SaluranMengundi;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpsertSaluranMengundiRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
$pusatMengundi = $this->route('pusatMengundi');
$pusatId = $pusatMengundi instanceof PusatMengundi ? $pusatMengundi->id : null;
$saluranMengundi = $this->route('saluranMengundi');
$saluranId = $saluranMengundi instanceof SaluranMengundi ? $saluranMengundi->id : null;
return [
'number' => [
'required',
'string',
'max:20',
Rule::unique('saluran_mengundis', 'number')
->where(fn ($query) => $query->where('pusat_mengundi_id', $pusatId))
->ignore($saluranId),
],
'voter_count' => ['nullable', 'integer', 'min:0'],
];
}
}