first
This commit is contained in:
50
app/Http/Requests/Admin/Setup/UpsertPusatMengundiRequest.php
Normal file
50
app/Http/Requests/Admin/Setup/UpsertPusatMengundiRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use App\Models\PusatMengundi;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpsertPusatMengundiRequest 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;
|
||||
$operationalQuantity = $this->isMethod('post') ? ['required', 'integer'] : ['sometimes', 'integer'];
|
||||
|
||||
return [
|
||||
'election_id' => ['required', 'integer', 'exists:elections,id'],
|
||||
'dun_id' => ['nullable', 'integer', 'exists:duns,id'],
|
||||
'code' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:50',
|
||||
Rule::unique('pusat_mengundis', 'code')
|
||||
->where(fn ($query) => $query->where('election_id', $this->input('election_id')))
|
||||
->ignore($pusatId),
|
||||
],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'address' => ['nullable', 'string', 'max:2000'],
|
||||
'saluran_count' => [...$operationalQuantity, 'min:1', 'max:100'],
|
||||
'ktm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'polis_iring_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'kp_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'ppm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'kpdp_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'papm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'jkm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'kkm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'calon_tambahan_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user