-1

I want clone Products from my Database with an Button click.

Example:

In my Product List i have create an Item successful. I want now add an second similar Item but dont want create an new Product and fill out the fields again (Takes time). I want now add an Button in my Laravel 5 Store where Duplicate or Clone the item where i have created before successful.

Just an new Database table with an other Product ID but all other the same info.

Whats the best way to do this?

Many Thanks

birdyfly
  • 3
  • 2

1 Answers1

5

With Eloquent you have a function replicate(), this will "clone" the object including relations.

Sample:

$product = Product::find(1);
$newProduct = $product->replicate();
$newProduct->save();
Maarten Peels
  • 1,002
  • 1
  • 13
  • 29