classes/Input/NestedModels.php
public function relateTo($model)
    {
        // Vars
        $relation_attributes = [];
        $input = Decoy::filteredInput();

        // Loop through the input, looking for relationships
        foreach ($input as $name => $data) {
            if (!$relation = $this->makeRelation($model, $name, $data)) {
                continue;
            }
            $relation_attributes[] = $name;

            // Write child data when the model is saved.  Because of how the saved
            // listener works, we need to explicitly make sure the saved model is
            // the one whose data we're parsing.
            $model::saved(function ($saved_model) use ($model, $relation, $name, $data) {
                if ($model != $saved_model) {
                    return;
                }
                $this->writeOnSaved($relation, $name, $data);
            });
        }

        // Returning all input without the related attribtues
        return array_except($input, $relation_attributes);
    }
public function relateTo($model)
    {
        // Vars
        $relation_attributes = [];
        $input = Decoy::filteredInput();

        // Loop through the input, looking for relationships
        foreach ($input as $name => $data) {
            if (!$relation = $this->makeRelation($model, $name, $data)) {
                continue;
            }
            $relation_attributes[] = $name;

            // Write child data when the model is saved.  Because of how the saved
            // listener works, we need to explicitly make sure the saved model is
            // the one whose data we're parsing.
            $model::saved(function ($saved_model) use ($model, $relation, $name, $data) {
                if ($model != $saved_model) {
                    return;
                }
                $this->writeOnSaved($relation, $name, $data);
            });
        }

        // Returning all input without the related attribtues
        return array_except($input, $relation_attributes);
    }
public function relateTo ( $ model ) { // Vars $ relation_attributes = [ ] ; $ input = Decoy :: filteredInput ( ) ; // Loop through the input, looking for relationships foreach ( $ input as $ name => $ data ) { if ( ! $ relation = $ this -> makeRelation ( $ model , $ name , $ data ) ) { continue ; } $ relation_attributes [ ] = $ name ; // Write child data when the model is saved.  Because of how the saved // listener works, we need to explicitly make sure the saved model is // the one whose data we're parsing. $ model :: saved ( function ( $ saved_model ) use ( $ model , $ relation , $ name , $ data ) { if ( $ model != $ saved_model ) { return ; } $ this -> writeOnSaved ( $ relation , $ name , $ data ) ; } ) ; } // Returning all input without the related attribtues return array_except ( $ input , $ relation_attributes ) ; }
Check the input for related models data.  Remove it from the input if it
exists.  And then listen for the model to be saved and write the related
models.

@param  Eloquent\Model $model
@return array          The input with attributes that were relations removed
Check the input for related models data . Remove it from the input if it exists . And then listen for the model to be saved and write the related models .