Advertisement
dotphp

paginate and having clause

Oct 11th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. var table_module = "calls";
  2. ------------------------------------------------------
  3. $result     = $this->model_class::select(DB::raw($this->table_module.".*,
  4.                                             sys_rel.rel_to_module as module_name,
  5.                                             sys_rel.rel_to_id as module_id,
  6.                                             (CASE rel_to_module
  7.                                                     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)
  8.                                                 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)
  9.                                                 WHEN sys_rel.rel_to_module = 'org'  THEN ( SELECT org_name FROM org WHERE org.org_serial_id = module_id LIMIT 1)
  10.                                                 WHEN sys_rel.rel_to_module is NULL THEN '-'
  11.                                         END) as calls_parent_id"))
  12.                                             ->leftjoin('sys_rel', $this->table_module.'.rel_serial_id', '=', 'sys_rel.rel_serial_id')
  13.                                             ->where('company_id', '=', $company_id)
  14.                                             ->where('deleted', '=', 0)
  15.                                             ->where($this->table_module.'.rel_serial_id', '>', 0)
  16.                                             ->having('calls_parent_id', 'LIKE', '%Wehner%')
  17.                                             ->get()->toArray();
  18.                                             //or ->paginate(10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement