I am trying to find a raw which satisfies, most conditions.
I have a model called SLA
; I am trying to find one SLA
.
I have 2 SLAs
SLA1 : type = 1
SLA2 type = 1 department = 2
When I call:
sla($type=1,$user_id=“”,$dept=“”,$source=“”,$priority=“”);
it returns SLA1
. When I call:
sla($type=1,$user_id=“”,$dept=1,$source=“”,$priority=“”);
it returns SLA1
instead of SLA2
. Here's my code:
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());
}