[英]How to convert this MySQL query to a equivalent Laravel 5.4 Elequent/query builder query?
SELECT `id` FROM `jobs` WHERE `job_type` IN ( 'topemployercheckbox1','topemployercheckbox2') OR `job_category` IN ( 'Contract','Intern') ;
我需要將此MySQL查詢轉換為laravel 5.4查詢生成器查詢。
你可以做
ModelName::whereIn('job_type',['topemployercheckbox1','topemployercheckbox2'])
->orwhere(function($q){
$q->whereIn('job_category',['Contract','Intern'])
})->get('id');
要么
ModelName::whereIn('job_type',['topemployercheckbox1','topemployercheckbox2'])
->whereIn('job_category',['Contract','Intern'],'or')->get('id');
您可以使用兩個whereIn查詢的並集。
$query1= \DB::table("jobs")select("id")->whereIn("job_type",['topemployercheckbox1','topemployercheckbox2']);
$query2=\DB::table("jobs")select("id")->whereIn("job_category",['Contract','Intern']);
$job_ids= $query1->union($query2)->get();
您的查詢將如下所示。 在這里,我們已經考慮到您的型號名稱為Job。
Job::select('id')
->whereIn('job_type',['topemployercheckbox1','topemployercheckbox2'])
->orWhereIn('job_category',['Contract','Intern'])
->get();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.