first
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use App\Models\DaerahMengundi;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpsertDaerahMengundiRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasRole('Admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$daerah = $this->route('daerahMengundi');
|
||||
|
||||
return [
|
||||
'election_id' => ['required', 'exists:elections,id'],
|
||||
'bahagian_pilihanraya_id' => ['required', 'exists:bahagian_pilihanrayas,id'],
|
||||
'code' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:50',
|
||||
Rule::unique('daerah_mengundis', 'code')
|
||||
->where('election_id', $this->input('election_id'))
|
||||
->ignore($daerah instanceof DaerahMengundi ? $daerah->id : null),
|
||||
],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user