protected function applyListParentToQuery($query)
    {
        if ( ! $this->listParentRelation) {

            if ($this->showsTopParentsOnly()) {
                $query->has($this->getModelInformation()->list->default_top_relation, '<', 1);
            }

            return $this;
        }

        // Use list parent information collected to get the model
        /** @var ListParentData $parentInfo */
        $parentInfo = array_last($this->listParents);

        if ( ! $parentInfo) {
            return $this;
        }

        // For morph relation, we need a special query
        $relationInstance = $query->getModel()->{$this->listParentRelation}();
        if ($relationInstance instanceof MorphTo) {

            $separator = $this->getListParentMorphKeySeparator();

            // If parent record indicator $key does not contain class/key separator symbol, ignore
            if (false === strpos($this->listParentRecordKey, $separator)) {
                return $this;
            }

            list($parentType, $parentKey) = explode($separator, $this->listParentRecordKey, 2);

            $parentType = $this->getRelationMappedMorphType($parentType);

            $query
                ->withoutGlobalScopes()
                ->where($query->getModel()->getTable() . '.' . $relationInstance->getMorphType(), $parentType)
                ->where($relationInstance->getQualifiedForeignKey(), $parentKey);

            return $this;
        }

        $query->whereHas($this->listParentRelation, function ($query) use ($parentInfo) {
            /** @var Builder $query */
            $query
                ->withoutGlobalScopes()
                ->where($parentInfo->model->getKeyName(), $this->listParentRecordKey);
        });

        return $this;
    }
protected function applyListParentToQuery($query)
    {
        if ( ! $this->listParentRelation) {

            if ($this->showsTopParentsOnly()) {
                $query->has($this->getModelInformation()->list->default_top_relation, '<', 1);
            }

            return $this;
        }

        // Use list parent information collected to get the model
        /** @var ListParentData $parentInfo */
        $parentInfo = array_last($this->listParents);

        if ( ! $parentInfo) {
            return $this;
        }

        // For morph relation, we need a special query
        $relationInstance = $query->getModel()->{$this->listParentRelation}();
        if ($relationInstance instanceof MorphTo) {

            $separator = $this->getListParentMorphKeySeparator();

            // If parent record indicator $key does not contain class/key separator symbol, ignore
            if (false === strpos($this->listParentRecordKey, $separator)) {
                return $this;
            }

            list($parentType, $parentKey) = explode($separator, $this->listParentRecordKey, 2);

            $parentType = $this->getRelationMappedMorphType($parentType);

            $query
                ->withoutGlobalScopes()
                ->where($query->getModel()->getTable() . '.' . $relationInstance->getMorphType(), $parentType)
                ->where($relationInstance->getQualifiedForeignKey(), $parentKey);

            return $this;
        }

        $query->whereHas($this->listParentRelation, function ($query) use ($parentInfo) {
            /** @var Builder $query */
            $query
                ->withoutGlobalScopes()
                ->where($parentInfo->model->getKeyName(), $this->listParentRecordKey);
        });

        return $this;
    }
protected function applyListParentToQuery ( $ query ) { if ( ! $ this -> listParentRelation ) { if ( $ this -> showsTopParentsOnly ( ) ) { $ query -> has ( $ this -> getModelInformation ( ) -> list -> default_top_relation , '<' , 1 ) ; } return $ this ; } // Use list parent information collected to get the model /** @var ListParentData $parentInfo */ $ parentInfo = array_last ( $ this -> listParents ) ; if ( ! $ parentInfo ) { return $ this ; } // For morph relation, we need a special query $ relationInstance = $ query -> getModel ( ) -> { $ this -> listParentRelation } ( ) ; if ( $ relationInstance instanceof MorphTo ) { $ separator = $ this -> getListParentMorphKeySeparator ( ) ; // If parent record indicator $key does not contain class/key separator symbol, ignore if ( false === strpos ( $ this -> listParentRecordKey , $ separator ) ) { return $ this ; } list ( $ parentType , $ parentKey ) = explode ( $ separator , $ this -> listParentRecordKey , 2 ) ; $ parentType = $ this -> getRelationMappedMorphType ( $ parentType ) ; $ query -> withoutGlobalScopes ( ) -> where ( $ query -> getModel ( ) -> getTable ( ) . '.' . $ relationInstance -> getMorphType ( ) , $ parentType ) -> where ( $ relationInstance -> getQualifiedForeignKey ( ) , $ parentKey ) ; return $ this ; } $ query -> whereHas ( $ this -> listParentRelation , function ( $ query ) use ( $ parentInfo ) { /** @var Builder $query */ $ query -> withoutGlobalScopes ( ) -> where ( $ parentInfo -> model -> getKeyName ( ) , $ this -> listParentRecordKey ) ; } ) ; return $ this ; }
Applies the active list parent as a filter on a query builder.

@param Builder $query
@return $this
Applies the active list parent as a filter on a query builder .