0

I have a model called CustomerInfo and i am trying to update it. update returns true but the changes are not reflecting on my db.

$customerInfo = CustomerInfo::where('machine_name',$username)->firstOrFail();
$result = $customerInfo->update($data);

$data varaible is a array having key value pair. Also tried the following

$customerInfo = CustomerInfo::where('machine_name',$username)->update($data);

3 Answers3

0

make sure $data variable that you want update record by its values, not be same with that record. in this case, you don't have sql error but return of update will be zero.

0
$result = $customerInfo->update($data);

$result variable will return only the boolean value. Try to return $customerInfo i.e.

return response()->json($customerInfo);

This will help you to find the actual problem and make sure the CustmerInfo model contains fillable properties and the $data variable contains all the information.

Try to use dd() like below to identify the issue:

dd($variable);  
Rwd
  • 34,180
  • 6
  • 64
  • 78
0

Solved my questions. Thanks Luciano. i started eloquent manual db transaction and forgot to commit it at the end

DB::beginTransaction();//did this
$customerInfo = CustomerInfo::where('machine_name',$username)->firstOrFail();
$result = $customerInfo->update($data);
DB::Commit() //forgot to implement this part.