时间:2022-05-28 08:45:47 | 栏目:PHP代码 | 点击:次
在sql语句执行前
DB::enableQueryLog();
sql sql sql sql sql
dd(DB::getQueryLog());
DB::enableQueryLog(); $data = UsersMenu::select('users_menu.*') ->join('users as a','a.id','=','users_menu.user_id') ->where('a.id', $user_id)->get(); // dd($data); // DB::connection()->enableQueryLog(); // $data = DB::query('select * from users_menu,users where users.id = users_menu.user_id'); dd(DB::getQueryLog());
附:whereIn 后面跟的参数必须是数组
普通sql语句:SELECT users_menu . *
FROM users_menu
INNER JOIN users AS a ON a.id = users_menu.user_id
WHERE a.id
IN ( 1, 2 )
$data = UsersMenu::select('users_menu.*') ->join('users as a','a.id','=','users_menu.user_id') ->whereIn('a.id', $user_id);
此时的$user_id 是个数组才行