I've the below code snippet to update a MySQL table. I'm testing my back-end with POSTMAN PUT request. This code doesn't seem to update MySQL correctly, instead it sets the MySQL cells to empty values, even though I'm getting "Updated Successfully" in my POSTMAN result.
Below is the Lumen PHP code
public function updateSensorPackage(Request $request, $id){
$sensorPackage = AddSensorPackage:: find($id);
$sensorPackage -> elderly_id = $request -> input('elderly_id');
$sensorPackage -> centre_id = $request -> input('centre_id');
$sensorPackage -> package_id = $request -> input('package_id');
$sensorPackage -> beacon_id = $request -> input('beacon_id');
$sensorPackage -> created_by = $request -> input('created_by');
$sensorPackage -> save();
return response('Updated Successfully', 200);
}
I set the POSTMAN header to "Content-type : Application/json" and sending the parameters in request body. Below I've pasted the POSTMAN "PUT" request.
After running dd($request->all());
I got the below result
My PHP version is 7+ and Lumen version is 5.5.2
$sensorPackage->update();
instead – Hussein$request->elderly_id
– HusseinAddSensorPackage
's$fillable
property contains an array with all the fields you want to update? – Ivanka Todorova$fillable
has to do with mass assignment, which is not his case – Hussein