Provides a simple way to duplicate a model instance.
Requirements:
- PHP >= 5.4
- Laravel 4.2
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.*"
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();
- Finish documentation