Sitemap
Dev Talk

Dev Talk

Software Engineer with extensive experience in full-stack web development, specializing in Laravel, JavaScript, and scalable backend systems.

Member-only story

Laravel replicate(): Duplicate Eloquent Models Safely

4 min readOct 24, 2026

--

Press enter or click to view image in full size

“Duplicate this” buttons look easy: copy the row, save it, done. Then the first copy fails with a duplicate-key error, or the new post comes out already deleted, or it quietly carries over an API token and a view count from the original. Eloquent has a built-in method for this, replicate(), and it handles more than people expect. It also leaves a few traps. I ran every example on Laravel 13.35.0 against a real database, so the results below are what actually happened.

The basic example

This one comes from the Laravel documentation. A shipping address becomes a billing address with one changed field:

$shipping = Address::create([
'type' => 'shipping',
'line_1' => '123 Example Street',
'city' => 'Victorville',
]);

$billing = $shipping->replicate()->fill([
'type' => 'billing',
]);

$billing->save();

After this, the table had two rows: id 1 ( shipping) and id 2 ( billing), both with the same street. The key point from the docs: replicate() returns an unsaved copy. Nothing is written until you call save().

What replicate() leaves out automatically

In the framework source, the method skips these on its own: the primary key, the created_at and updated_at columns, any columns…

--

--

Dev Talk
Dev Talk

Written by Dev Talk

Software Engineer with extensive experience in full-stack web development, specializing in Laravel, JavaScript, and scalable backend systems.