Posts Learn Components new Snippets new Categories Tags About Device Beast sponsor

How to Replicate Laravel Model

Learn how to easily replicate or clone your Laravel model

Created on Jul 12, 2021


Sometimes you might need to replicate or clone your model and to do that you can make use of the "replicate" method available by the "Model" instance itself.

Imagine you have a "Post" model and you want to replicate it, you can do so like below.
// retrieve the first post
$post = Post::first();

// replicate the first post and save it as a new post

Now when you have a look on the database, you will have a new record with the same exact content as the one you have replicated but with a different "id" (identifier) since it's unique.

Snippets by

PostSrc poster


Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

Load comments for How to Replicate Laravel Model


PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that are right for your project.

View Components

Other Code Snippets