Looking to hire Laravel developers? Try LaraJobs

laravel-deep-replicate maintained by pharaonic

Last update
2026/11/12 14:23 (dev-develop)
License
Links
Downloads
0

Comments
comments powered by Disqus

Installation

composer require pharaonic/laravel-deep-replicate

The service provider and the DeepReplicate facade are registered automatically. There is nothing to publish or migrate.

Usage

use Pharaonic\Laravel\DeepReplicate\Facades\DeepReplicate;

$result = DeepReplicate::for($order)
    ->copy('items', 'items.options')   // new items and options for the new order
    ->reuse('items.product', 'customer') // link to the existing products and customer
    ->skip('payments')
    ->with(['status' => 'draft'])
    ->replicate();                      // one transaction

$copy = $result->model();               // the new, persisted order
$result->map()->get($oldItem);          // the copy of an original item
$result->stats()->copiedModels();       // root + items + options

Or add the trait to the model and start from the model itself; it returns the same builder:

use Pharaonic\Laravel\DeepReplicate\Concerns\DeepReplicates;

class Order extends Model
{
    use DeepReplicates;
}

$result = $order->deepReplicate('items', 'items.options')
    ->reuse('items.product', 'customer')
    ->replicate();

Laravel's own replicate() is untouched. At least one relation must always be selected.

Documentation

Full documentation: Deep Replicate Documentation.

Support & Security

See SUPPORT.md and SECURITY.md. Contributions are welcome; see CONTRIBUTING.md.

License

MIT. See LICENSE.