Route::get('test', function () {
DB::connection()->enableQueryLog();
// Get the executed query array
Users::with('posts')->get();
dd(DB::getQueryLog());
});
array:2 [▼
0 => array:3 [▼
"query" => "select * from `users`"
"bindings" => []
"time" => 2.76
]
1 => array:3 [▼
"query" => "select * from `posts` where `posts`.`users_id` in (?, ?)"
"bindings" => array:2 [▶]
"time" => 0.71
]
]
In the above code, why not select id from user and then use this query result in the next step?