Eager load sample

3 years ago

lloricode

Code

ray()->showQueries();

User::with('profile:first_name,last_name')
  ->select('email')
  ->get();

Output

[!] Aliasing 'User' to 'App\Models\Auth\User' for this Tinker session.
=> Illuminate\Database\Eloquent\Collection {#4002
     all: [
       App\Models\Auth\User {#4029
         email: "[email protected]",
         profile: null,
       },
       App\Models\Auth\User {#4028
         email: "[email protected]",
         profile: null,
       },
       App\Models\Auth\User {#4018
         email: "[email protected]",
         profile: null,
       },
       App\Models\Auth\User {#4030
         email: "[email protected]",
         profile: null,
       },
       App\Models\Auth\User {#4043
         email: "[email protected]",
         profile: null,
       },
       App\Models\Auth\User {#4045
         email: "[email protected]",
         profile: null,
       },
       App\Models\Auth\User {#4024
         email: "[email protected]",
         profile: null,
       },
       App\Models\Auth\User {#4020
         email: "[email protected]",
         profile: null,
       },
       App\Models\Auth\User {#4023
         email: "[email protected]",
         profile: null,
       },
       App\Models\Auth\User {#4021
         email: "[email protected]",
         profile: null,
       },
     ],
   }
HELO: Local email testing for your desktop!