[筆記]Laravel 利用Eloquent進行不分大小寫查詢

一般如果自己下SQL語法,只要將二邊都Upper即可,但利用Eloquent就是不用自己下語法

原了可以抽換資料庫,不自己下SQL,認份的查了Eloquent的用法,原來很簡單,本來用Like的,改用iLike即可,這樣即會進行模糊比對,而且不分大小寫喔

        $qryarray=[];
        $subqryarray=[]; 

        if ($request->has('AccountNo')){
            $qryarray = array_add($qryarray, "AccountNo",['ilike','%'.$request->input("AccountNo").'%']);            
        }     

        if ($request->has('ChineseName')){            
            $subqryarray = array_add($subqryarray, "ChineseName",['like','%'.$request->input("ChineseName").'%']);
        }        
        if ($request->has('EngName')){
            $subqryarray = array_add($subqryarray, "EngName",['ilike','%'.$request->input("EngName").'%']);
        }   
        if(count($subqryarray)>0) {
            $qryarray=  array_add($qryarray, 'subQuery1',['or',$subqryarray] );
            $subqryarray=[];
        }
        if ($request->has('DisplayName')){
            $qryarray = array_add($qryarray, "DisplayName",['like','%'.$request->input("DisplayName").'%']);
        }           
        if ($request->has('CompanyMail')){
            $qryarray = array_add($qryarray, "CompanyMail", ['like','%'.$request->input("CompanyMail").'%']);
        }     
        $this->repository->setscope($qryarray);

 

打雜打久了,就變成打雜妹

程式寫久了,就變成老乞丐