I'm sure there has to be a quicker way to do the following. I wasn't able to find anything about how to save a laravel modal object as a new row without overwriting the existing item. Essentially, a simpler of my existing code:
$oldItem = Item::find(1);
$newItem = new Item;
$newItem->key = $oldItem ->key;
$newItem->name = $oldItem ->name;
$newItem->path = $oldItem ->path;
$newItem->save();
Instead, copying everything but the id of the row:
$oldItem = Item::find(1);
$newItem = $oldItem;
unset($newItem->id);
$newItem->save();
You can try
$newItem = Item::find(1)->replicate()->save();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With