bavix / laravel-wallet

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

How to remove global scope on eager loading #980

Closed ISNewton closed 4 months ago

ISNewton commented 4 months ago

Describe your task Hi there, How to disable the default where slug = default scope where eager loading the wallet :

        $teachers = Teacher::query()
            ->with('wallet' ,function($query){
                $query->select('balance' , 'meta');
            })
            ->whereHas('wallet' , function ($query) use ($request) {
                $query
                    ->where('slug', Teacher::getInstitutionWalletKey($request->institution->id));
            })
            ->get()
        ;

This generates the following query:

"select * from `users` where exists (select * from `wallets` where `users`.`id` = `wallets`.`holder_id` and `wallets`.`holder_type` = ? and `slug` = ? and `slug` = ?)"

How to get rid of the extra where slug clause that comes with from the package?

ISNewton commented 4 months ago

This is solved by querying the wallets relation instead of wallet