I'm trying to update multiple rows based on its unique field taskCode
and will update the field of taskWeight from tbl_projtask
I have this 2 variable
$request->dataWeightThis variable is coming from ajax request that contains something like this95,75,65a value that is separated by commas.$request->dataWeightAttrThis variable is coming from ajax request that contains something like thisTaskCode1, TaskCode2, TaskCode3
In my MainController.php
I have this code
$myString = $request->dataWeightAttr;
foreach($myString as $value){
DB::table('tbl_projtask')
->where('taskCode', $value)
->update([
'taskWeight'=> $request->dataWeight,
'by_id'=> auth()->user()->id,
'updated_by'=> auth()->user()->name,
'updated_at' => now()
]);
}
As you can see in my update code
I used request->dataWeightAttr to find which rows should be updated and $request->dataWeight the value for specific taskCode
Am I doing this right?
$request->dataWeightAttr