public function mutateToOrigin($result, $attributes)
    {
        $mutations = [];

        // Transform mutations back to their origin
        foreach ($attributes as $mutation => $values)
        {
            // First we should see whether this mutation can be resolved so that
            // we take it into consideration otherwise we skip to the next iteration.
            if ( ! $this->resolvableMutation($mutation)) continue;
            // Since this mutation should be resolved by us then we check whether it is
            // a Many or One mutation.
            if ($this->isManyMutation($mutation))
            {
                return $this->mutateManyToOrigin($attributes);
            }
            // Dealing with Morphing relations requires that we determine the morph_type out of the relationship
            // and mutating back to that class.
            elseif ($this->isMorphMutation($mutation))
            {
                $mutant = $this->mutateMorphToOrigin($result, $attributes);

                if ($this->getMutation($mutation)['type'] == 'morphEager')
                {
                    $mutations[$mutation] = $mutant;
                } else {
                    $mutations = reset($mutant);
                }
            }
            // Dealing with One mutations is simply returning an associative array with the mutation
            // label being the $key and the related model is $value.
            else
            {
                $model = $this->getMutationModel($mutation)->newFromBuilder($values);
                $model->setConnection($model->getConnectionName());
                $mutations[$mutation] = $model;
            }
        }

        return $mutations;
    }
public function mutateToOrigin($result, $attributes)
    {
        $mutations = [];

        // Transform mutations back to their origin
        foreach ($attributes as $mutation => $values)
        {
            // First we should see whether this mutation can be resolved so that
            // we take it into consideration otherwise we skip to the next iteration.
            if ( ! $this->resolvableMutation($mutation)) continue;
            // Since this mutation should be resolved by us then we check whether it is
            // a Many or One mutation.
            if ($this->isManyMutation($mutation))
            {
                return $this->mutateManyToOrigin($attributes);
            }
            // Dealing with Morphing relations requires that we determine the morph_type out of the relationship
            // and mutating back to that class.
            elseif ($this->isMorphMutation($mutation))
            {
                $mutant = $this->mutateMorphToOrigin($result, $attributes);

                if ($this->getMutation($mutation)['type'] == 'morphEager')
                {
                    $mutations[$mutation] = $mutant;
                } else {
                    $mutations = reset($mutant);
                }
            }
            // Dealing with One mutations is simply returning an associative array with the mutation
            // label being the $key and the related model is $value.
            else
            {
                $model = $this->getMutationModel($mutation)->newFromBuilder($values);
                $model->setConnection($model->getConnectionName());
                $mutations[$mutation] = $model;
            }
        }

        return $mutations;
    }
public function mutateToOrigin ( $ result , $ attributes ) { $ mutations = [ ] ; // Transform mutations back to their origin foreach ( $ attributes as $ mutation => $ values ) { // First we should see whether this mutation can be resolved so that // we take it into consideration otherwise we skip to the next iteration. if ( ! $ this -> resolvableMutation ( $ mutation ) ) continue ; // Since this mutation should be resolved by us then we check whether it is // a Many or One mutation. if ( $ this -> isManyMutation ( $ mutation ) ) { return $ this -> mutateManyToOrigin ( $ attributes ) ; } // Dealing with Morphing relations requires that we determine the morph_type out of the relationship // and mutating back to that class. elseif ( $ this -> isMorphMutation ( $ mutation ) ) { $ mutant = $ this -> mutateMorphToOrigin ( $ result , $ attributes ) ; if ( $ this -> getMutation ( $ mutation ) [ 'type' ] == 'morphEager' ) { $ mutations [ $ mutation ] = $ mutant ; } else { $ mutations = reset ( $ mutant ) ; } } // Dealing with One mutations is simply returning an associative array with the mutation // label being the $key and the related model is $value. else { $ model = $ this -> getMutationModel ( $ mutation ) -> newFromBuilder ( $ values ) ; $ model -> setConnection ( $ model -> getConnectionName ( ) ) ; $ mutations [ $ mutation ] = $ model ; } } return $ mutations ; }
Mutate a result back into its original Model.

@param  mixed $result
@param  array $attributes
@return array
Mutate a result back into its original Model .