37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Master;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class DepartmentRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user()->can($this->isMethod('post') ? 'create-departments' : 'update-departments');
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'code' => [
|
|
'required',
|
|
'string',
|
|
'max:10',
|
|
Rule::unique('departments')->ignore($this->route('department')),
|
|
],
|
|
'name' => ['required', 'string', 'max:100'],
|
|
'degree_level' => ['nullable', 'string', Rule::in(['D3', 'D4', 'S1', 'S2', 'S3'])],
|
|
'lecturer_id' => [
|
|
'nullable',
|
|
Rule::requiredIf($this->route('department') !== null),
|
|
'integer',
|
|
Rule::exists('lecturer_department', 'lecturer_id')
|
|
->where('department_id', $this->route('department')?->id ?? 0),
|
|
],
|
|
'leadership_started_at' => ['nullable', 'date', 'required_with:lecturer_id'],
|
|
];
|
|
}
|
|
}
|