Illuminate\Database\Eloquent\Relations\BelongsTo::associate PHP Метод

associate() публичный Метод

Associate the model instance to the given parent.
public associate ( Model | integer $model ) : Model
$model Illuminate\Database\Eloquent\Model | integer
Результат Illuminate\Database\Eloquent\Model
    public function associate($model)
    {
        $otherKey = $model instanceof Model ? $model->getAttribute($this->otherKey) : $model;
        $this->parent->setAttribute($this->foreignKey, $otherKey);
        if ($model instanceof Model) {
            $this->parent->setRelation($this->relation, $model);
        }
        return $this->parent;
    }

Usage Example

Пример #1
2
 public static function setBelongsTo(BelongsTo $belongsTo, $object = null)
 {
     return $object ? $belongsTo->associate($object) : $belongsTo->dissociate();
 }
All Usage Examples Of Illuminate\Database\Eloquent\Relations\BelongsTo::associate