Level 8
You need to use replicate().
foreach ($records as $record) {
$record->replicate();
$record->save();
}
Here is the documentation link: https://laravel.com/docs/8.x/eloquent#replicating-models
I want each of selected records reinsert into table as a new row (so they get highest ID + current created_at) and delete old row.
$records = Record::where('board_id', 2)->......blah blah......->get();
foreach ($records as $record) {
$newRecord = New Record();
//???
}
You need to use replicate().
foreach ($records as $record) {
$record->replicate();
$record->save();
}
Here is the documentation link: https://laravel.com/docs/8.x/eloquent#replicating-models
Please or to participate in this conversation.