src/Entities/Entity.php
public function copy($attributes = [])
    {
        // copy attributes
        $new = $this->replicate();
        
        // fill attributes resource
        $new->fill($attributes);
        
        // save model before you recreate relations (so it has an id)
        $new->save();
        
        // re-sync everything
        foreach ($this->relations as $relationName => $values) {
            if ($new->{$relationName}() instanceof \Illuminate\Database\Eloquent\Relations\BelongsToMany) {
                $new->{$relationName}()->sync($values);
            } else {
                $new->{$relationName}()->attach($values);
            }
        }
        
        return $new;
    }
public function copy($attributes = [])
    {
        // copy attributes
        $new = $this->replicate();
        
        // fill attributes resource
        $new->fill($attributes);
        
        // save model before you recreate relations (so it has an id)
        $new->save();
        
        // re-sync everything
        foreach ($this->relations as $relationName => $values) {
            if ($new->{$relationName}() instanceof \Illuminate\Database\Eloquent\Relations\BelongsToMany) {
                $new->{$relationName}()->sync($values);
            } else {
                $new->{$relationName}()->attach($values);
            }
        }
        
        return $new;
    }
public function copy ( $ attributes = [ ] ) { // copy attributes $ new = $ this -> replicate ( ) ; // fill attributes resource $ new -> fill ( $ attributes ) ; // save model before you recreate relations (so it has an id) $ new -> save ( ) ; // re-sync everything foreach ( $ this -> relations as $ relationName => $ values ) { if ( $ new -> { $ relationName } ( ) instanceof \ Illuminate \ Database \ Eloquent \ Relations \ BelongsToMany ) { $ new -> { $ relationName } ( ) -> sync ( $ values ) ; } else { $ new -> { $ relationName } ( ) -> attach ( $ values ) ; } } return $ new ; }
Copia a entidade e suas relações

@return object
Copia a entidade e suas relações