Hydrate the pivot table relationship on the models.

@param  array  $models
@return void
431099
protected function hydratePivotRelation(array $models)
    {
        // To hydrate the pivot relationship, we will just gather the pivot attributes
        // and create a new Pivot model, which is basically a dynamic model that we
        // will set the attributes, table, and connections on it so it will work.
        foreach ($models as $model) {
            $model->setRelation('pivot', $this->newExistingPivot(
                $this->migratePivotAttributes($model)
            ));
        }
    }
1146008
public function setExtraModelValues(array $fields, &$model)
    {
        //make sure the relationships are loaded
        foreach ($fields as $name => $field) {
            if ($field->getOption('relationship')) {
                $this->setModelRelationship($model, $field);
            }

            //if this is a setter field, unset it
            if ($field->getOption('setter')) {
                $model->__unset($name);
            }
        }
    }
1063101
protected function assignRelations($relations)
    {
        foreach ($relations as $relation) {
            if (!$relation instanceof RelationInterface) {
                throw new ModelException(sprintf('Relation must be an instance of RelationInterface, got "%s"', $this->getType($relation)));
            }

            foreach (array_keys($relation->keys()) as $field) {
                $this->assertField($field);
            }

            $this->relations[$relation->name()] = $relation;
        }
    }
805227
public function addEagerConstraints(array $models)
    {
        $this->query->whereIn($this->foreignKey, $this->getKeys($models, $this->localKey));
    }
1213748
public function flush($model)
    {
        if (! $this->shouldMaintainIndex($model)) {
            return;
        }

        $indexColumn = $this->getIndexColumn($model);

        $this->database
            ->table($model->searchableAs())
            ->update([$indexColumn => null]);
    }
1227504
public function deleteModels(Models $models)
    {
        foreach ($models as $model) {
            $this->dispatchBeforeEvent($model, Event::DELETE);
        }

        $this->deleteAll()->executeModels($models);

        foreach ($models as $model) {
            $this->dispatchAfterEvent($model, Event::DELETE);
        }

        return $this;
    }
76112
protected function getEagerModelKeys(array $models)
    {
        $keys = array();

        /**
         * First we need to gather all of the keys from the parent models so we know what
         * to query for via the eager loading query. We will add them to an array then
         * execute a "where in" statement to gather up all of those related records.
         */
        foreach ($models as $model)
        {
            // In the case of fetching nested relations, we will get an array
            // with the first key being the model we need, and the other being
            // the related model so we'll just take the first model out of the array.
            if (is_array($model)) $model = reset($model);

            if ( ! is_null($value = $model->{$this->ownerKey}))
            {
                $keys[] = $value;
            }
        }

        /**
         * If there are no keys that were not null we will just return an empty array in
         * it so the query doesn't fail, but will not return any results, which should
         * be what this developer is expecting in a case where this happens to them.
         */
        if (count($keys) == 0)
        {
            return array();
        }

        return array_values(array_unique($keys));
    }
490202
protected function setRelations($values)
    {
        if (isset($values[0]->belongsTo)) {
            $this->relations['belongsTo'] = $values[0]->belongsTo;
        }

        if (isset($values[0]->belongsToMany)) {
            $this->relations['belongsToMany'] = $values[0]->belongsToMany;
        }

        if (isset($values[0]->hasOne)) {
            $this->relations['hasOne'] = $values[0]->hasOne;
        }

        if (isset($values[0]->hasMany)) {
            $this->relations['hasMany'] = $values[0]->hasMany;
        }

        if (isset($values[0]->hasManyThrough)) {
            $this->relations['hasManyThrough'] = $values[0]->hasManyThrough;
        }
    }
492988
protected function hydrateValueObjects(&$attributes)
    {
        foreach ($this->entityMap->getEmbeddables() as $localKey => $valueClass) {
            $this->hydrateValueObject($attributes, $localKey, $valueClass);
        }
    }
1024297
public function update($models)
    {
        if ($models->isEmpty()) {
            return;
        }

        $index = $this->algolia->initIndex($models->first()->searchableAs());

        if ($this->usesSoftDelete($models->first()) && $this->softDelete) {
            $models->each->pushSoftDeleteMetadata();
        }

        $objects = $models->map(function ($model) {
            if (empty($searchableData = $model->toSearchableArray())) {
                return;
            }

            return array_merge(
                ['objectID' => $model->getScoutKey()],
                $searchableData,
                $model->scoutMetadata()
            );
        })->filter()->values()->all();

        if (! empty($objects)) {
            $index->saveObjects($objects);
        }
    }
178503
public function initRelation(array $models, $relation)
    {
        foreach ($models as $model) {
            $model->setRelation($relation, []);
        }
        return $models;
    }
827950
public function syncRelationships(array $relationships)
    {
        foreach ($relationships as $relation) {
            if (in_array($relation, $this->needSync)) {
                $this->synchronize($relation);
            }
        }
    }
223308
public function removeAll(array $entities): void
    {
        if ([] === $entities) {
            return;
        }
        foreach ($entities as $entity) {
            $this->checkIsCorrectEntityType($entity);
            $this->entityManager->remove($entity);
        }

        $this->entityManager->flush();
    }
1335674
protected function processAllAttachments(Collection $models)
    {
        $progress = $this->getProgressBar($models);
        $progress->start();

        foreach ($models as $model) {
            $progress->advance();

            foreach ($model->getAttachedFiles() as $attachedFile) {
                $attachedFile->reprocess();
            }
        }

        $progress->finish();
    }
916288
protected function setModels($models): self
    {
        // We can not use the collect() helper here, since we require this
        // to be an Eloquent Collection
        $this->models = $models instanceof EloquentCollection
            ? $models
            : new EloquentCollection($models);

        return $this;
    }
792813
protected  function processSomeAttachments($models, $attachments)
	{
		foreach ($models as $model) 
		{
			foreach ($model->getAttachedFiles() as $attachedFile) 
			{
				if (in_array($attachedFile->name, $attachments)) {
					$attachedFile->reprocess();
				}
			}
		}
	}
360108
public function addEagerConstraints(array $models)
    {
        /**
         * We'll grab the primary key name of the related models since it could be set to
         * a non-standard name and not "id". We will then construct the constraint for
         * our eagerly loading query so it returns the proper models from execution.
         */

        // Grab the parent node placeholder
        $parentNode = $this->query->getQuery()->modelAsNode($this->parent->getTable());

        // Tell the builder to select both models of the relationship
        $this->query->select($this->relation, $parentNode);

        // Setup for their mutation so they don't breed weird stuff like... humans ?!
        $this->query->addManyMutation($this->relation, $this->related);
        $this->query->addManyMutation($parentNode, $this->parent);

        // Set the parent node's placeholder as the RETURN key.
        $this->query->getQuery()->from = array($parentNode);
        // Build the MATCH ()-[]->() Cypher clause.
        $this->query->matchOut($this->parent, $this->related, $this->relation, $this->foreignKey, $this->localKey, $this->parent->{$this->localKey});
        // Add WHERE clause over the parent node's matching keys [values...].
        $this->query->whereIn($this->localKey, $this->getKeys($models));
    }