|string> */ public function rules(): array { // if parent_id was not passed in, validate from root $parent_id = !$this->parent_id ? File::query()->whereIsRoot()->where('created_by', Auth::id())->first() : $this->parent_id; // merge parent ParentIDBaseRequest rules with new rule return array_merge(parent::rules(), [ // require folder name, must be unique in the DB, made by the current user, with parent_id, and not marked as deleted 'name' => [ 'required', Rule::unique(File::class, 'name') ->where('created_by', Auth::id()) ->where('parent_id', $parent_id) ->whereNull('deleted_at') ] ] ); } public function messages() { return [ 'name.unique' => 'Folder ":input" already exists' ]; } }