����JFIF��x�x����'
Server IP : 66.29.137.217 / Your IP : 216.73.216.29 Web Server : LiteSpeed System : Linux premium294.web-hosting.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : gltevjme ( 1095) PHP Version : 7.0.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/gltevjme/./cbt.bofirm.com/vendor/bavix/laravel-wallet/docs/_include/ |
Upload File : |
## Eager Loading When accessing Eloquent relationships as properties, the relationship data is "lazy loaded". This means the relationship data is not actually loaded until you first access the property. However, Eloquent can "eager load" relationships at the time you query the parent model. Eager loading alleviates the N + 1 query problem. To illustrate the N + 1 query problem, consider a `Wallet` model that is related to `User`: Add the `HasWallet` trait and `Wallet` interface to model. ```php use Bavix\Wallet\Traits\HasWallet; use Bavix\Wallet\Interfaces\Wallet; class User extends Model implements Wallet { use HasWallet; // public function wallet(): MorphOne... } ``` Now, let's retrieve all wallets and their users: ```php $users = User::all(); foreach ($users as $user) { // echo $user->wallet->balance; echo $user->balance; // Abbreviated notation } ``` This loop will execute 1 query to retrieve all of the users on the table, then another query for each user to retrieve the wallet. So, if we have 25 users, the code above would run 26 queries: 1 for the original user, and 25 additional queries to retrieve the wallet of each user. Thankfully, we can use eager loading to reduce this operation to just 2 queries. When querying, you may specify which relationships should be eager loaded using the with method: ```php $users = User::with('wallet')->all(); foreach ($users as $user) { // echo $user->wallet->balance; echo $user->balance; // Abbreviated notation } ``` For this operation, only two queries will be executed.