You can use the replicate method. This will create a new object with the same values ββexcept the primary key and timestamps. After that you can save your model:
$task = Task::find(1); $new = $task->replicate();
If you want, you can change the property
$new->project = $otherProject;
and then
$new->save();
if you want a new id just:
$newID = $new->id;
source share