Your IP : 216.73.216.79


Current Path : /var/www/html/reddsis/app/Http/Requests/Backend/
Upload File :
Current File : /var/www/html/reddsis/app/Http/Requests/Backend/ContentDirectoryDepartmentRequest.php

<?php

namespace App\Http\Requests\Backend;

use Illuminate\Foundation\Http\FormRequest;

class ContentDirectoryDepartmentRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        $departmentId = $this->route('id');

        return [
            'directory_department_code' => 'nullable|string|max:255',
            'directory_department_name' => 'required|string|max:255',
            'directory_department_name_en' => 'nullable|string|max:255',
            'directory_department_parent_id' => [
                'nullable',
                'integer',
                'exists:content_directory_departments,directory_department_id',
                function ($attribute, $value, $fail) use ($departmentId) {
                    if ($value && $departmentId && (int) $value === (int) $departmentId) {
                        $fail('A department cannot be its own parent.');
                    }
                },
            ],
            'directory_department_sort' => 'nullable|integer',
        ];
    }
}