Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

qyioma's avatar

Call to undefined method stdClass::update()

Can someone explain to me why this error happen. Below is my code.

public function update(Request $request) //14
{
$searchBarcodeID = $request->label_ID;
$edit_1 = IncomingGetweight::where('label_ID', $searchBarcodeID)->first();
$edit_2 = InprocessGetWeight::where('label_ID', $searchBarcodeID)->first();
$edit_3 = WireGetweight::where('label_ID', $searchBarcodeID)->first();
$edit_4 = InternalscrapGetWeight::where('label_ID', $searchBarcodeID)->first();
$edit_5 = Baler::where('label_ID', $searchBarcodeID)->first();
$edit_6 = ReturnGetweight::where('label_ID', $searchBarcodeID)->first();
$edit_7 = SearchBarcode::where('label_ID', $searchBarcodeID)->first();


// Update each database column with the data submitted from the edit form

$edit_1->PO = $request->PO;
$edit_1->PO_line = $request->PO_line;
$edit_1->invoice = $request->invoice;
$edit_1->label_ID = $request->label_ID;
$edit_1->brand = $request->brand;
$edit_1->date_received = $request->date_received;

$edit_2->invoice = $request->invoice;
$edit_2->label_ID = $request->label_ID;
$edit_2->part_no = $request->part_no;
$edit_2->description = $request->description;
$edit_2->date_received = $request->date_received;

$edit_3->invoice = $request->invoice;
$edit_3->label_ID = $request->label_ID;
$edit_3->part_no = $request->part_no;
$edit_3->work_order = $request->work_order;
$edit_3->status = $request->status;
$edit_3->date_received = $request->date_received;

$edit_4->invoice = $request->invoice;
$edit_4->label_ID = $request->label_ID;
$edit_4->part_no = $request->part_no;
$edit_4->work_order = $request->work_order;
$edit_4->date_received = $request->date_received;

$edit_5->invoice = $request->invoice;
$edit_5->label_ID = $request->label_ID;
$edit_5->part_no = $request->part_no;
$edit_5->work_order = $request->work_order;
$edit_5->date_received = $request->date_received;

$edit_6->invoice = $request->invoice;
$edit_6->label_ID = $request->label_ID;
$edit_6->part_no = $request->part_no;
$edit_6->type = $request->type;
$edit_6->sales_order = $request->sales_order;
$edit_6->sales_order_line = $request->sales_order_line;
$edit_6->date_received = $request->date_received;


$edit_7->PO = $request->PO;
$edit_7->PO_line = $request->PO_line;
$edit_7->invoice = $request->invoice;
$edit_7->label_ID = $request->label_ID;
$edit_7->brand = $request->brand;
$edit_7->part_no = $request->part_no;
$edit_7->description = $request->description;
$edit_7->work_order = $request->work_order;
$edit_7->type = $request->type;
$edit_7->sales_order = $request->sales_order;
$edit_7->sales_order_line = $request->sales_order_line;
$edit_7->date_received = $request->date_received;

$edit_1->update();
$edit_2->update();
$edit_3->update();
$edit_4->update();
$edit_5->update();
$edit_6->update();
$edit_7->update();

return redirect()->route('frontend.praiBarcode.reweight_search')->withFlashSuccess('Barcode record updated successfully!'); 
}
0 likes
3 replies
LaryAI's avatar
Level 58

It looks like you are trying to call the update() method on the $edit_1, $edit_2, $edit_3, $edit_4, $edit_5, $edit_6, and $edit_7 variables. However, these variables are instances of stdClass, which does not have an update() method.

You need to use the Eloquent ORM to update the records in the database. For example, to update the IncomingGetweight record, you would use the following code:

$edit_1 = IncomingGetweight::where('label_ID', $searchBarcodeID)->first();

$edit_1->PO = $request->PO;
$edit_1->PO_line = $request->PO_line;
$edit_1->invoice = $request->invoice;
$edit_1->label_ID = $request->label_ID;
$edit_1->brand = $request->brand;
$edit_1->date_received = $request->date_received;

$edit_1->save();

You would need to do the same for the other records.

jlrdw's avatar

@qyioma explain better what you are trying to do please. I've dwelt with business invoices for almost 40 years, but have never quite seen code like that.

You need to make a relation, main invoice is parent, line items is the child table. Just suggestion.

And what did not work from @laryai answer.

  • did you try save
  • what errors did you get
  • what does the network tab show
  • do you have your protected $fillable

Please or to participate in this conversation.