Trying to get property ‘wallet’ of non-object


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


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;

        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

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


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