parent = File::query()->where('id', $this->input('parent_id'))->first(); // if there is a a parent but it is not owned by the user if ($this->parent && !$this->parent->isOwner(Auth::id())) { // stop return false; } // otherwise continue return true; } /** * Get the validation rules that apply to the request. * * @return array|string> */ public function rules(): array { // validate parent id return [ 'parent_id' => [ Rule::exists(File::class, 'id') ->where(function (Builder $query) { return $query ->where('is_folder', '1') // must be a folder ->where('created_by', Auth::id()); // must be made by current user } ) ] ]; } }