1
我正在嘗試查找滿足大多數條件的原始數據。如何修改執行的Laravel查詢生成器
我有一個模型叫SLA
;我試圖找到一個SLA
。
我有2 SLAs
SLA1 : type = 1
SLA2 type = 1 department = 2
當我打電話:
sla($type=1,$user_id=「」,$dept=「」,$source=「」,$priority=「」);
它返回SLA1
。當我打電話:
sla($type=1,$user_id=「」,$dept=1,$source=「」,$priority=「」);
返回SLA1
而不是SLA2
。這裏是我的代碼:
function sla($type = "", $userid = "", $department = "", $source = "", $priority = "") {
$sla = \App\Model\helpdesk\Manage\Sla\Sla_plan::
where(function($query)use($type, $department, $source) {
$query->where(function($q) use($department) {
$q->whereRaw("find_in_set($department,apply_sla_depertment)");
})
->where(function($q) use($type) {
$q->whereRaw("find_in_set($type,apply_sla_tickettype)");
})
->where(function($q) use($source) {
$q->whereRaw("find_in_set($source,apply_sla_ticketsource)");
});
})
->orWhere(function($query)use($type, $department, $source) {
$query->orWhere(function($q) use($department) {
$q->whereRaw("find_in_set($department,apply_sla_depertment)");
})
->orWhere(function($q) use($type) {
$q->whereRaw("find_in_set($type,apply_sla_tickettype)");
})
->orWhere(function($q) use($source) {
$q->whereRaw("find_in_set($source,apply_sla_ticketsource)");
});
});
dd($sla->first());
}