pharaonic / laravel-deep-replicate
Replicate a chosen Eloquent relationship graph into new persisted records, with explicit copy, reuse, and skip rules per relation path.
Package info
github.com/Pharaonic/laravel-deep-replicate
pkg:composer/pharaonic/laravel-deep-replicate
Requires
- php: >=8.3 <8.6
- illuminate/container: ^13.0
- illuminate/contracts: ^13.0
- illuminate/database: ^13.0
- illuminate/support: ^13.0
Requires (Dev)
- laravel/pint: ^1.20
- orchestra/testbench: ^11.0
- pestphp/pest: ^4.0
- phpstan/phpstan: ^2.1.33
- phpunit/phpunit: ^12.5.8
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-develop
- 13.x-dev
- 13.0.0
- 12.x-dev
- 12.0.0
- 11.x-dev
- 11.0.0
- 10.x-dev
- 10.0.0
- 9.x-dev
- 9.0.0
- 8.x-dev
- 8.0.0
- 7.x-dev
- 7.0.0
- 6.x-dev
- 6.0.0
- dev-fix/pivot-class-10.x
- dev-fix/pivot-class-9.x
- dev-fix/pivot-class-8.x
- dev-fix/pivot-class-7.x
- dev-fix/pivot-class-6.x
- dev-fix/relation-generics-10.x
- dev-fix/relation-generics-9.x
- dev-fix/relation-generics-8.x
- dev-fix/relation-generics-7.x
- dev-fix/relation-generics-6.x
- dev-docs/cover
- dev-docs/cover-6.x
- dev-docs/cover-7.x
- dev-docs/cover-8.x
- dev-docs/cover-9.x
- dev-fix/morph-to-results-6.x
This package is auto-updated.
Last update: 2026-11-12 13:26:54 UTC
README
Replicate a chosen Eloquent relationship graph into new records, with explicit copy, reuse and skip rules.
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.
