$ show BKWLD/cloner
Cloner is a Laravel package that provides a trait for Eloquent models to duplicate models, their relationships, and file attachments. The core functionality resides in the Cloner service class which handles the cloning process, including relationship traversal and file duplication via an adapter pattern. The package supports cloning to the same or different database connections (with limitations for many-to-many relations across databases) and fires events during the cloning process. It is designed as a reusable library for Laravel applications, with a service provider for easy integration.
The LLM identified 3 files worth highlighting for reuse:
The core cloning service that handles duplicating Eloquent models, their relationships (including many-to-many and one-to-many), and file attachments via an adapter. It demonstrates good separation of concerns, uses dependency injection for the attachment adapter and event dispatcher, and provides extension points via model callbacks and Laravel events.
A trait that adds cloning capabilities to Eloquent models. It provides methods to define exempt attributes, file attributes, and relations to clone, along with lifecycle callbacks (onCloning, onCloned). This allows models to be extended with cloning functionality in a non-intrusive, reusable way.
A simple interface that defines the contract for duplicating file attachments. It allows different storage systems (like the provided Upchuck adapter) to be plugged in, demonstrating the adapter pattern and promoting loose coupling between the cloning logic and file storage implementation.