Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $items = DB::table("calls")->select(DB::raw("calls.*,
- sys_rel.rel_to_module as module_name,
- sys_rel.rel_to_id as module_id,
- (CASE rel_to_module
- WHEN sys_rel.rel_to_module = 'leads' THEN ( SELECT CONCAT(leads.leads_first_name, ' ', leads.leads_last_name) FROM leads WHERE leads.leads_serial_id = module_id LIMIT 1)
- WHEN sys_rel.rel_to_module = 'contacts' THEN ( SELECT CONCAT(contacts.contacts_first_name, ' ', contacts.contacts_last_name) FROM contacts WHERE contacts.contacts_serial_id = module_id LIMIT 1)
- WHEN sys_rel.rel_to_module = 'org' THEN ( SELECT org_name FROM org WHERE org.org_serial_id = module_id LIMIT 1)
- WHEN sys_rel.rel_to_module is NULL THEN '-'
- END) as calls_parent_id"))
- ->leftjoin('sys_rel', 'calls.rel_serial_id', '=', 'sys_rel.rel_serial_id')
- ->where('company_id', '=', '1')
- ->where('deleted', '=', 0)
- ->where('calls.rel_serial_id', '>', 0)
- ->having('calls_parent_id', 'LIKE', '%Wehner%')
- ->get();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement