Вход Регистрация
Файл: vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphMany.php
Строк: 95
<?php

namespace IlluminateDatabaseEloquentRelations;

use 
IlluminateDatabaseEloquentCollection as EloquentCollection;

/**
 * @template TRelatedModel of IlluminateDatabaseEloquentModel
 * @template TDeclaringModel of IlluminateDatabaseEloquentModel
 *
 * @extends IlluminateDatabaseEloquentRelationsMorphOneOrMany<TRelatedModel, TDeclaringModel, IlluminateDatabaseEloquentCollection<int, TRelatedModel>>
 */
class MorphMany extends MorphOneOrMany
{
    
/**
     * Convert the relationship to a "morph one" relationship.
     *
     * @return IlluminateDatabaseEloquentRelationsMorphOne<TRelatedModel, TDeclaringModel>
     */
    
public function one()
    {
        return 
MorphOne::noConstraints(fn () => tap(
            new 
MorphOne(
                
$this->getQuery(),
                
$this->getParent(),
                
$this->morphType,
                
$this->foreignKey,
                
$this->localKey
            
),
            function (
$morphOne) {
                if (
$inverse $this->getInverseRelationship()) {
                    
$morphOne->inverse($inverse);
                }
            }
        ));
    }

    
/** @inheritDoc */
    
public function getResults()
    {
        return ! 
is_null($this->getParentKey())
            ? 
$this->query->get()
            : 
$this->related->newCollection();
    }

    
/** @inheritDoc */
    
public function initRelation(array $models$relation)
    {
        foreach (
$models as $model) {
            
$model->setRelation($relation$this->related->newCollection());
        }

        return 
$models;
    }

    
/** @inheritDoc */
    
public function match(array $modelsEloquentCollection $results$relation)
    {
        return 
$this->matchMany($models$results$relation);
    }

    
/** @inheritDoc */
    
public function forceCreate(array $attributes = [])
    {
        
$attributes[$this->getMorphType()] = $this->morphClass;

        return 
parent::forceCreate($attributes);
    }
}
Онлайн: 2
Реклама