'required|integer', 'name' => 'required|min_length[2]|max_length[100]', 'mobile' => 'required|min_length[10]|max_length[20]', ]; protected $validationMessages = [ 'lead_id' => [ 'required' => 'Lead ID is required', ], 'name' => [ 'required' => 'Contact person name is required', ], 'mobile' => [ 'required' => 'Mobile number is required', ], ]; protected $skipValidation = false; /** * Get all contacts for a lead */ public function getContactsByLead($leadId) { return $this->where('lead_id', $leadId) ->orderBy('is_primary', 'DESC') ->findAll(); } /** * Get primary contact for a lead */ public function getPrimaryContact($leadId) { return $this->where('lead_id', $leadId) ->where('is_primary', 1) ->first(); } /** * Set a contact as primary (unset others) */ public function setPrimaryContact($contactId, $leadId) { $this->db->transStart(); // Unset all primary contacts for this lead $this->where('lead_id', $leadId) ->set(['is_primary' => 0]) ->update(); // Set the specified contact as primary $this->update($contactId, ['is_primary' => 1]); $this->db->transComplete(); return $this->db->transStatus(); } }