bavix / laravel-wallet

It's easy to work with a virtual wallet
https://bavix.github.io/laravel-wallet/
MIT License
1.14k stars 229 forks source link

Trying to get property 'balance' of non-object #477

Closed masitings closed 2 years ago

masitings commented 2 years ago

Describe your task Hi guys, i have a problem when i want to get the balance from the default wallet.

To Reproduce Steps to reproduce the behavior:

  1. I have put the same exact tutorial from the Basic Usage of the Documentation on User model, this is my code
    
    namespace App\Models;

use Bavix\Wallet\Interfaces\Customer; use Bavix\Wallet\Interfaces\Wallet; use Bavix\Wallet\Traits\CanPay; use Bavix\Wallet\Traits\HasWallet; use Bpuig\Subby\Traits\HasSubscriptions; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; use Ramsey\Uuid\Uuid; use Staudenmeir\EloquentHasManyDeep\HasRelationships;

class User extends Authenticatable implements Wallet, Customer { use HasApiTokens, HasFactory, Notifiable, HasSubscriptions, HasWallet, CanPay, HasRelationships; /**

  1. And nothing happen here until i try test to see if its works using TestController that i've create :
    public function index()
    {
    $user = auth()->user();
    return $user->balance;
    }

Expected behavior I just want it works on my application and it seems didn't work out.

Server:

rez1dent3 commented 2 years ago

@masitings Hello.

Trying to get property 'balance' of non-object

You are trying to get balance from null. Apparently you don't have a user in the request.