How I can update multiple objects with CONCAT in a single query?
The following code works, but it is not safe:
Table::whereIn('id', $idArray)->where('user_id', $this->userId)
->update([
'title' => DB::raw('CONCAT(title,'.$form->newPart.')')
]);
Another method that I have tried is the following, however it does not work:
Table::whereIn('id', $idArray)->where('user_id', $this->userId)
->update([
'title' => DB::raw('CONCAT(title,?)', [$form->newPart])
]);
I think you will just have to call the setBindings method.
Table::whereIn('id', $idArray)->where('user_id', $this->userId)
->update([
'title' => DB::raw('CONCAT(title, ?)')
])
->setBindings([$form->newPart]);
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