0

how to write like this. this function is not working for me

ContractorsServices::where('serviceID',$request->id)->where('isPopular', false)->update([
    'isPopular' => true
]);
Marwelln
  • 28,492
  • 21
  • 93
  • 117

2 Answers2

0

try doing it this way

ContractorsServices::where(['serviceID' => $request->id, 'isPopular' => 'false'])
->update([
    'isPopular' => true
]);

It's VIN
  • 152
  • 7
-1

use:

ContractorsServices::where([
      ['serviceID',$request->id],
      ['isPopular', false]
    ])
    ->update([
       'isPopular' => true
    ]); 

if not work, check data is correct or not:

$ContractorsServices = ContractorsServices::where([
  ['serviceID',$request->id],
  ['isPopular', false]
])->get();

 return $ContractorsServices;
  • it still dont works, response is [{"id":31,"contractorID":11,"serviceID":34,"price":1500,"isPopular":false,"relativePositionNumber":null,"comment":null,"updated_at":"2022-08-06T13:10:41.000000Z","created_at":"2022-08-05T06:21:10.000000Z"}] – Dias Oralbekov Aug 06 '22 at 13:13
  • maybe update is not working? – Dias Oralbekov Aug 06 '22 at 13:15
  • check `$ContractorsServices = ContractorsServices::where([ ['serviceID',$request->id], ['isPopular', false] ])->get(); return $ContractorsServices;` if it is work and return data you can set `update()` instead `get()`, also you can get the data like first code in this comment and do this: `foreach($ContractorsServices as $conser) { $conser->isPopular = false; }` after foreach `$ContractorsServices->save();` – Hosserin Ibrahim Aug 07 '22 at 08:24