lucasmichot/eloquentcopy

This package is abandoned and no longer maintained. No replacement package was suggested.

Provides a simple way to duplicate a model instance

0.1 2014-07-08 09:53 UTC

This package is auto-updated.

Last update: 2024-12-16 21:18:51 UTC


README

Provides a simple way to duplicate a model instance.

Requirements:

Package installation

Begin by installing this package through Composer. Edit your project's composer.json file to require lucasmichot/eloquentcopy.

"require": {
  "lucasmichot/eloquentcopy": "0.*"
}

Next, update Composer from the Terminal:

$ composer update

You can achieve these operations with this one-liner command :

$ composer require "lucasmichot/eloquentcopy:0.*"

Usage

use Lucasmichot\Eloquentcopy\CopyTrait;

class Post extends Eloquent
{
    use CopyTrait;

    // the code of your model comes here
}

Copying an instance of the model :

$firstPost = Post::create([
	'title' => 'Foo',
	'text'  => 'Sample text',
]);

$secondPost = $firstPost->copy();
// $secondPost has no ID, no created_at and no updated_at attribute

$secondPost->save();

TODO

  • Finish documentation