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);
CodePudding user response:
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.
CodePudding user response:
$result = $customerInfo->update($data);
$result variable will return only the boolean value. try to return $customerInfo. i.e,
return response()->json($customerInfo);
then you can find the issue. and make sure CustmerInfo model contains fillable properties, and $data variable contains all the information. try to use dd() like below to identify the issue, dd($variable);
CodePudding user response:
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.