Clone an existing Eloquent model instance into a new, unsaved model while resetting primary keys and timestamps.
When duplicating complex records (such as cloning an invoice, template, or draft post), copying individual attributes manually is error-prone.
The replicate() method creates a copy of an existing model instance, clearing primary keys and timestamp values automatically so it can be saved as a new database row.
Basic Cloning
use App\Models\Invoice;
$invoice = Invoice::find(1);
// Clones attributes into a new unsaved instance
$newInvoice = $invoice->replicate();
$newInvoice->invoice_number = 'INV-2026-002';
$newInvoice->save();
Excluding Specific Columns
Pass an array of attribute names to exclude them from the cloned model:
use App\Models\Post;
$post = Post::find(10);
// Duplicate the post, resetting view counts and publication status
$draft = $post->replicate([
'slug',
'views_count',
'is_published',
'published_at',
]);
$draft->title = 'Copy of ' . $post->title;
$draft->save();
Summary
- Clears the model primary key (
idor custom key) andcreated_at/updated_attimestamps. - Accepts an array of attribute exceptions to prevent sensitive or unique columns from copying.
- Returns a fresh, unsaved model instance ready for customization before calling
save().
Related Tips
View all tips →Refresh and Pessimistically Lock Models with refreshForUpdate() in Laravel 13.27
Laravel 13.27 adds refreshForUpdate(), reloading an existing model instance in-place with fresh database attributes while acquiring an exclusive FOR UPDATE row lock.
Scope Pivot Table Queries with Closures in wherePivot() in Laravel 13.26
Laravel 13.26 allows wherePivot() and orWherePivot() to accept closures, enabling direct reuse of local scopes defined on custom Pivot models.