Eloquent model update returns true but db change not reflecting

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);


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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.

Method 3

$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:


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x