I am trying to update data with where condition. I am trying to get the where condition of update statement from the select statement. But in this case the data is not updated.
public function update(string $id, Request $request)
{
$select_id = Finish::select('id')->where('id', $id)->distinct()->first();
return ($select_id); // response === {"id":36}
// this can update data
Finish::where('id', $id)->update([
'remarks1' => $request->formData['remarks1']
]);
// this can't update data, why???
Finish::where('id', $select_id)->update([
'remarks1' => $request->formData['remarks1']
]);
return response()->json(['status' => '200']);
}
Why is it so?
->first(). This returns a model or null, it does not return a value. You could do this with->value('id')tho