Skip to content

Zero wallet balance when querying the wallet with Query Builder #993

@hacktolove

Description

@hacktolove

Describe the bug
When using the Laravel Query Builder I get the balance as 0 , But when I switch to Laravel Eloquent ORM I get the correct balance 5000.

        $student = User::find(1);

        $wallet = $student->createWallet([
            'name' => 'Student wallet',
            'slug' => 'MyUniqueSlug',
            'meta' => ['is_active' => true]
        ]);

        $wallet->deposit(5000);

Now this query will return the correct wallet but with the balance 0:

        $students = DB::table('users')
            ->join('wallets', function ($join){
                $join->on('wallets.holder_id', 'users.id')
                    ->where('wallets.holder_type', User::class)
                    ->where('wallets.slug', 'MyUniqueSlug');
                ;
            })

But this query will return the correct wallet with the correct balance 5000

        $students = Student::query()
            ->withWhere('wallets', function ($query) {
                $query->where('wallets.slug' , 'MyUniqueSlug',);
            })
            ->get();

I can confirm that the transactions was created.

To Reproduce
Steps to reproduce the behavior:

  1. Create a user wallet
  2. Deposit 5000
  3. Query the wallet with both ORM and Query Builder
  4. You should see different balances.

Server:

  • php version: 8.3
  • database: 8.0.3
  • wallet version 10.1.6

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions