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

namespace IlluminateDatabaseEloquentRelations;

use 
IlluminateDatabaseEloquentCollection as EloquentCollection;

/**
 * @template TRelatedModel of IlluminateDatabaseEloquentModel
 * @template TDeclaringModel of IlluminateDatabaseEloquentModel
 *
 * @extends IlluminateDatabaseEloquentRelationsHasOneOrMany<TRelatedModel, TDeclaringModel, IlluminateDatabaseEloquentCollection<int, TRelatedModel>>
 */
class HasMany extends HasOneOrMany
{
    
/**
     * Convert the relationship to a "has one" relationship.
     *
     * @return IlluminateDatabaseEloquentRelationsHasOne<TRelatedModel, TDeclaringModel>
     */
    
public function one()
    {
        return 
HasOne::noConstraints(fn () => tap(
            new 
HasOne(
                
$this->getQuery(),
                
$this->parent,
                
$this->foreignKey,
                
$this->localKey
            
),
            function (
$hasOne) {
                if (
$inverse $this->getInverseRelationship()) {
                    
$hasOne->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);
    }
}
Онлайн: 3
Реклама