php - Laravel4 duplicate / copy table row -


i'm sure there has quicker way following. wasn't able find how save laravel modal object new row without overwriting existing item. essentially, simpler of 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 id of row:

$olditem = item::find(1); $newitem = $olditem; unset($newitem->id); $newitem->save(); 

you can try

$newitem = item::find(1)->replicate()->save(); 

Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -