Trying to get property ‘wallet’ of non-object

Published

I’m getting Trying to get property of non-object while trying to this code:

//QuestController

public function reward(Quest $quest){
        $users = User::find($quest->accepter_id);
        $own = (auth()->user());
        $quest = Quest::find($quest->id);

        $wallet = $users->wallet; //error started here
        $own_wallet = $own->wallet;

        $users->wallet = $wallet + $quest->reward; //here also
        $own->wallet = $own_wallet - $quest->reward;
        $quest->rewarded = true;
        
        $users->save();
        $own->save();
        $quest->save();

        return redirect()->route('quest.index')->with('success',"Reward SENT successfully");
    }

I tried using the [”] but it gave an error of

Creating default object from empty value

Source: Laravel

Published
Categorised as controller, laravel, laravel-8, object, php Tagged , , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq