我想将此mySQL更改为Laravels ORM

时间:2018-11-30 13:36:30

标签: php mysql laravel

MySQL查询:

ManagementObjectSearcher comPortSearcher = new ManagementObjectSearcher(@"\\localhost\root\CIMV2", "SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0");

        using (comPortSearcher)
        {
            string caption = null;
            foreach (ManagementObject obj in comPortSearcher.Get())
            {
                if (obj != null)
                {
                    object captionObj = obj["Caption"];
                    if (captionObj != null)
                    {
                        caption = captionObj.ToString();
                            if (caption.Contains("CH340"))
                            {
                                _currentSerialSettings.PortName = caption.Substring(caption.LastIndexOf("(COM")).Replace("(", string.Empty).Replace(")", string.Empty);
                            }
                    }
                }
            }
        }

1 个答案:

答案 0 :(得分:0)

尝试这种方式:

DB::table('vote_checks')
->select(DB::raw('COUNT(DISTINCT vote_checks.user_id) as count')
->leftJoin('vote_items','vote_checks.item_id', '=', 'vote_items.id')
->where('vote_items.vote_id',3)
->get();