Вход Регистрация
Файл: system/vendor/illuminate/database/Eloquent/Relations/MorphOne.php
Строк: 79
<?php

namespace IlluminateDatabaseEloquentRelations;

use 
IlluminateDatabaseEloquentCollection;
use 
IlluminateDatabaseEloquentModel;
use 
IlluminateDatabaseEloquentRelationsConcernsSupportsDefaultModels;

class 
MorphOne extends MorphOneOrMany
{
    use 
SupportsDefaultModels;

    
/**
     * Get the results of the relationship.
     *
     * @return mixed
     */
    
public function getResults()
    {
        if (
is_null($this->getParentKey())) {
            return 
$this->getDefaultFor($this->parent);
        }

        return 
$this->query->first() ?: $this->getDefaultFor($this->parent);
    }

    
/**
     * Initialize the relation on a set of models.
     *
     * @param  array  $models
     * @param  string  $relation
     * @return array
     */
    
public function initRelation(array $models$relation)
    {
        foreach (
$models as $model) {
            
$model->setRelation($relation$this->getDefaultFor($model));
        }

        return 
$models;
    }

    
/**
     * Match the eagerly loaded results to their parents.
     *
     * @param  array  $models
     * @param  IlluminateDatabaseEloquentCollection  $results
     * @param  string  $relation
     * @return array
     */
    
public function match(array $modelsCollection $results$relation)
    {
        return 
$this->matchOne($models$results$relation);
    }

    
/**
     * Make a new related instance for the given model.
     *
     * @param  IlluminateDatabaseEloquentModel  $parent
     * @return IlluminateDatabaseEloquentModel
     */
    
public function newRelatedInstanceFor(Model $parent)
    {
        return 
$this->related->newInstance()
                    ->
setAttribute($this->getForeignKeyName(), $parent->{$this->localKey})
                    ->
setAttribute($this->getMorphType(), $this->morphClass);
    }
}
Онлайн: 0
Реклама