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