src/Traits/WorksWithRelations.php
protected function updateOrCreateHasMany(array $fillable, Model $model, Relation $relation)
    {
        $keys = [];
        $id = '';
        $records = [];

        foreach ($fillable as $fields) {
            if (is_array($fields)) {
                if (array_key_exists('id', $fields)) {
                    $id = $fields['id'];
                }

                if (array_except($fields, ['id'])) {
                    $record = $relation->updateOrCreate(['id' => $id], $fields);
                    array_push($keys, $record->id);
                    array_push($records, $record);
                }
            } else {
                if (array_except($fillable, ['id'])) {
                    $record = $relation->updateOrCreate(['id' => $id], $fillable);
                    array_push($keys, $record->id);
                    array_push($records, $record);
                }
            }
        }

        if ($keys && (property_exists($this, 'pruneHasMany') && $this->pruneHasMany !== false)) {
            $notIn = $relation->getRelated()->whereNotIn('id', $keys)->get();
            foreach ($notIn as $record) {
                $record->delete();
            }
        }

        return $records;
    }
protected function updateOrCreateHasMany(array $fillable, Model $model, Relation $relation)
    {
        $keys = [];
        $id = '';
        $records = [];

        foreach ($fillable as $fields) {
            if (is_array($fields)) {
                if (array_key_exists('id', $fields)) {
                    $id = $fields['id'];
                }

                if (array_except($fields, ['id'])) {
                    $record = $relation->updateOrCreate(['id' => $id], $fields);
                    array_push($keys, $record->id);
                    array_push($records, $record);
                }
            } else {
                if (array_except($fillable, ['id'])) {
                    $record = $relation->updateOrCreate(['id' => $id], $fillable);
                    array_push($keys, $record->id);
                    array_push($records, $record);
                }
            }
        }

        if ($keys && (property_exists($this, 'pruneHasMany') && $this->pruneHasMany !== false)) {
            $notIn = $relation->getRelated()->whereNotIn('id', $keys)->get();
            foreach ($notIn as $record) {
                $record->delete();
            }
        }

        return $records;
    }
protected function updateOrCreateHasMany ( array $ fillable , Model $ model , Relation $ relation ) { $ keys = [ ] ; $ id = '' ; $ records = [ ] ; foreach ( $ fillable as $ fields ) { if ( is_array ( $ fields ) ) { if ( array_key_exists ( 'id' , $ fields ) ) { $ id = $ fields [ 'id' ] ; } if ( array_except ( $ fields , [ 'id' ] ) ) { $ record = $ relation -> updateOrCreate ( [ 'id' => $ id ] , $ fields ) ; array_push ( $ keys , $ record -> id ) ; array_push ( $ records , $ record ) ; } } else { if ( array_except ( $ fillable , [ 'id' ] ) ) { $ record = $ relation -> updateOrCreate ( [ 'id' => $ id ] , $ fillable ) ; array_push ( $ keys , $ record -> id ) ; array_push ( $ records , $ record ) ; } } } if ( $ keys && ( property_exists ( $ this , 'pruneHasMany' ) && $ this -> pruneHasMany !== false ) ) { $ notIn = $ relation -> getRelated ( ) -> whereNotIn ( 'id' , $ keys ) -> get ( ) ; foreach ( $ notIn as $ record ) { $ record -> delete ( ) ; } } return $ records ; }
HasMany relation updateOrCreate logic.

@param array    $fillable The relation fillable.
@param Model    $model    The eloquent model.
@param Relation $relation The eloquent relation.

@return array
HasMany relation updateOrCreate logic .