Reputation: 1059
i have to copy a record from db I am trying this
$new_p = $p->replicate();
$new_p->save();
but Its not saved P model has many relations i dont know how to copy all !
Upvotes: 0
Views: 1765
Reputation: 8242
You have to attach the many to many relationships to the clone after saving it, something like this:
$new_p = $p->replicate();
$new_p->save();
$new_p->firstRelations()->attach($p->firstRelations);
$new_p->secondRelations()->attach($p->secondRelations);
Upvotes: 1