Skip to content
Advertisement

Attempt to assign property of non-object when updating the existing the record

I want to update some records from my table and if user has uploaded a picture, I need to upload it and update the seller_certificate_card as well.

Here is my code:

public function doStepTwo(Request $request, $id)
{
    $newSeller = Seller::where('id', $id)->update([
        'seller_first_name' => $request->fname_seller,
        'seller_last_name' => $request->lname_seller,
    ]);
    
    if($request->hasFile('upload_certificate'))
    {
        $destination_path = "public/images/sellers/$user_id";
        $image = $request->file('upload_certificate');
        $image_name = $image->getClientOriginalName();
        $path = $request->file('upload_shenasname')->storeAs($destination_path,$image_name);
        $newSeller->seller_certificate_card = $image_name;
        $newSeller->save();
    }
}

And the seller_certificate_card at the table has this structure:

seller_certificate_card varchar(255)

But I get this error:

Attempt to assign property ‘seller_certificate_card’ of non-object

So what’s going wrong here? How can I fix this issue?

Advertisement

Answer

$newSeller = Seller::where('id', $id)->first();
$newSeller->update([
    'seller_first_name' => $request->fname_seller,
    'seller_last_name' => $request->lname_seller,
]);

Try This.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement