朱纯树博客
VPS测评推荐网站
cloudacead cloudacead

laravel 子查询

public function test(Request $request){    

        $data=$request->all();;

        $where = [];  //用于外层查询条件

        $whereData = [];  //用于子查询条件

        if(!empty($data[‘device_group_id’])){  //管制区id

            $where[‘b.device_group_id’] = $whereData[‘device_group_id’] = $data[‘device_group_id’];

        }

        if(!empty($data[‘start_time’])){  //开始时间

            $whereData[‘start_time’] = $data[‘start_time’];

        }

        if(!empty($data[‘end_time’])){   //结束时间

            $whereData[‘end_time’] = $data[‘end_time’];

        }

        $data = DB::table(‘vip’. ‘ as a’)

            ->rightJoin(‘gate_role as b’,’a.id’,’=’,’b.vip_id’)   //有门禁权限的才记录

            ->where($where)

            ->whereNotIn(‘a.id’,function ($query) use($whereData){

                $query->from(‘device_group as c’)

                    ->leftJoin(‘device_device_group as d’, ‘c.id’, ‘=’, ‘d.device_group_id’)

                    ->leftJoin(‘device as e’, ‘d.device_id’, ‘=’, ‘e.id’)

                    ->leftJoin(‘visitor as f’, ‘e.mac’, ‘=’, ‘f.mac’)

                    ->where(‘c.id’, $whereData[‘device_group_id’])

                    ->whereBetween(‘f.discern_time’,[$whereData[‘start_time’],$whereData[‘end_time’]])

                    ->select(‘f.vip_id’);

            })

            ->orderBy(‘a.id’, ‘desc’)

            ->get(array(‘a.id’,’a.name’))

            ->map(function($value){

                return (array)$value;

            })->toArray();

        dd($data);

}

文章来源于互联网:laravel 子查询

赞(0) 打赏
未经允许不得转载:VPS测评推荐网站 - 朱纯树博客 » laravel 子查询

评论 8

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #0

    very nice submit, i actually love this web site, keep on it

    النفط21小时前回复
  2. #0

    You really make it seem so easy along with your presentation but I find this matter to be really something which I feel I might never understand. It seems too complicated and extremely large for me. I am looking ahead to your subsequent submit, I?ll attempt to get the hang of it!

  3. #0

    I think this is one of the most vital info for me. And i am glad reading your article. But want to remark on few general things, The web site style is ideal, the articles is really excellent : D. Good job, cheers

  4. #0

    Primary T cell lymphoma of the breast with lymphoepithelial lesion zithromax 250 price 13 15 Endometrial hyperplasia was also found to be more common among healthy women who received preventive tamoxifen compared with untreated women

    Inefeby2周前 (03-10)回复
  5. #0

    Results of Anastrozole Therapy to Date cialis professional 1995 Mar; 12 3 195- 7

    DeettyhoW2个月前 (02-07)回复
  6. #0
  7. #0

    You re not on your back, she says amazon priligy A clinicopathologic study of 63 cases

    DeettyhoW2个月前 (01-29)回复
  8. #0

    Jsososo : http://juyifb.com/

    东南亚小野猫1年前 (2022-01-07)回复