Route::get('test', function () {
DB::connection()->enableQueryLog();
// 取得已執行的查詢陣列
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
]
]
上述程式碼中 為什麼不是select id from user 然後把這個查詢結果用於下一步的in中 ,
雷雷