|string> */ public function rules(): array { $rule = []; if ($this->method() == "POST") { $rule = [ ...$rule, 'object_type' => [ 'required', new Enum(ApprovalObjectType::class), ], 'object_id' => [ 'required', function ($attribute, $value, $fail) { $exist = ApprovalObjectType::from($this->get("object_type")) ->modelBuilderAllowed($value) ->where("company_id", Auth::user()->company_id) ->where('id', $value) ->count(); if (! $exist) { $fail('Resources without permission to access.'); } } ], 'file_ids' => [ 'array', function ($attribute, $value, $fail) { $count = File::query() ->where("company_id", Auth::user()->company_id) ->whereIn('id', $value) ->where("object_type", FileObjectType::CONTAINER) ->where("object_id", $this->get("object_id")) ->where("approval_status", ObjectApprovalStatus::WAIT) ->count(); if ($count != count($value)) { $fail('Please select the file to be approved.'); } } ], 'approvalFlow_id' =>[ 'required', function ($attribute, $value, $fail) { $exist = ApprovalFlow::query() ->where("company_id", Auth::user()->company_id) ->where('id', $value) ->where('status', 1) ->count(); if (! $exist) { $fail('Resources without permission to access.'); } } ] ]; } return $rule; } }