select($columns)->where('is_active',1)->findAll(); foreach ($clients as &$client) { $clientPolicyModel = new ClientPolicyModel(); $clientPolicies = $clientPolicyModel->select(['client_policy.id','p.name']) ->join('policies p', 'p.id = client_policy.policy_id') ->where('client_policy.client_id',$client['id']) ->where('client_policy.is_active', 1) ->findAll(); $client['policies'] = $clientPolicies; } //print_r(($clients));die(); return $clients; } public function getCreatedByUserName(){ return $this->db->table('clients') ->select('clients.*') ->select('user_profiles.first_name as user_name') ->join('user_profiles', 'user_profiles.id = clients.created_by') ->get() ->getResult(); } }