我正在使用 laravel 我想从第一个表中获取记录,即使它不存在于第二个表中,但现在我只在两个表中都存在时才获取记录:
$module=DB::table('r_module')->leftJoin('r_perm','r_perm.module_id','=','r_module.id')->where('r_perm.role_id',$id)->orWhereNull('r_perm.role_id')->get();
Try like this:
$module=DB::table('r_module')
->leftJoin('r_perm','r_perm.module_id','=','r_module.id')
->where('r_perm.role_id', $id)
->orWhere('r_perm.role_id', 'IS NULL')
->get();
You can also debug that query with 'dd()' function like this:
dd(DB::table('r_module')
->leftJoin('r_perm','r_perm.module_id','=','r_module.id')
->where('r_perm.role_id', $id)
->orWhere('r_perm.role_id', 'IS NULL')
->toSql());
That should put you on the track to make it generated as you need it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.