Download the PHP package vdlp/eloquent-model-cloner without Composer

On this page you can find all versions of the php package vdlp/eloquent-model-cloner. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package eloquent-model-cloner

Eloquent model cloner

This package was inspired by https://github.com/BKWLD/cloner and modified to also work with OctoberCMS installations.

A trait for Laravel Eloquent models that lets you clone a model and it's relationships, including files. Even to another database.

Installation

To get started with the Eloquent Model Cloner, use Composer to add the package to your project's dependencies:

Usage

Your model should now look like this:

You can clone an Article model like so:

Cloning Relationships

Lets say your Article has many Photos (a one to many relationship) and can have more than one Authors (a many to many relationship). Now, your Article model should look like this:

The $cloneableRelations informs the Cloneable as to which relations it should follow when cloning. Now when you call Article::first()->duplicate(), all of the Photo rows of the original will be copied and associated with the new Article. And new pivot rows will be created associating the new Article with the Authors of the original (because it is a many to many relationship, no new Author rows are created). Furthermore, if the Photo model has many of some other model, you can specify $cloneableRelations in its class and Cloner will continue replicating them as well.

Customizing the cloned attributes

By default, Cloner does not copy the id (or whatever you've defined as the key for the model) field; it assumes a new value will be auto-incremented. It also does not copy the created_at or updated_at. You can add additional attributes to ignore as follows:

The $cloneExemptAttributes adds to the defaults. If you want to replace the defaults altogether, override the trait's getCloneExemptAttributes() method and return an array.

Also, note the onCloning() method in the example. It is being used to make sure a unique column stays unique. The Cloneable trait adds to no-op callbacks that get called immediately before a model is saved during a duplication and immediately after: onCloning() and onCloned(). The $child parameter allows you to customize the behavior based on if it's being cloned as a relation or direct.

In addition, Cloner fires events during cloning and when the model has been cloned, see:

The event payload contains the clone and the original model instances.


All versions of eloquent-model-cloner with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vdlp/eloquent-model-cloner contains the following files

Loading the files please wait ....