EloquentCopy
Provides a simple way to duplicate a model instance., (*1)
Requirements:
* PHP >= 5.4
* Laravel 4.2, (*2)
Package installation
Begin by installing this package through Composer. Edit your project's composer.json file to require lucasmichot/eloquentcopy., (*3)
"require": {
"lucasmichot/eloquentcopy": "0.*"
}
Next, update Composer from the Terminal:, (*4)
$ composer update
You can achieve these operations with this one-liner command :, (*5)
$ 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 :, (*6)
$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