From 6b94cb3293d7f71f4ba48471ad0128a37851ac88 Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Fri, 26 Sep 2025 10:00:06 +0700 Subject: [PATCH] fix ContactID null on contact_show --- app/Models/ContactModel.php | 62 +++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/app/Models/ContactModel.php b/app/Models/ContactModel.php index f76e86e..13b58d3 100644 --- a/app/Models/ContactModel.php +++ b/app/Models/ContactModel.php @@ -25,39 +25,41 @@ class ContactModel extends Model { public function getContactWithDetail($ContactID) { $rows = $this->where('contact.ContactID', $ContactID)->join('contactdetail cd', 'contact.ContactID=cd.ContactID','left')->get()->getResultArray(); - $contact = [ - 'ContactID' => $rows[0]['ContactID'], - 'NameFirst' => $rows[0]['NameFirst'] ?? null, - 'NameLast' => $rows[0]['NameLast'] ?? null, - 'Title' => $rows[0]['Title'] ?? null, - 'Initial' => $rows[0]['Initial'] ?? null, - 'Birthdate' => $rows[0]['Birthdate'] ?? null, - 'EmailAddress1' => $rows[0]['EmailAddress1'] ?? null, - 'EmailAddress2' => $rows[0]['EmailAddress2'] ?? null, - 'Phone' => $rows[0]['Phone'] ?? null, - 'MobilePhone1' => $rows[0]['MobilePhone1'] ?? null, - 'MobilePhone2' => $rows[0]['MobilePhone2'] ?? null, - 'Specialty' => $rows[0]['Specialty'] ?? null, - 'SubSpecialty' => $rows[0]['SubSpecialty'] ?? null, - 'Details' => [] - ]; + $contact = []; + if(!empty($rows)) { + $contact = [ + 'ContactID' => $rows[0]['ContactID'] ?? null, + 'NameFirst' => $rows[0]['NameFirst'] ?? null, + 'NameLast' => $rows[0]['NameLast'] ?? null, + 'Title' => $rows[0]['Title'] ?? null, + 'Initial' => $rows[0]['Initial'] ?? null, + 'Birthdate' => $rows[0]['Birthdate'] ?? null, + 'EmailAddress1' => $rows[0]['EmailAddress1'] ?? null, + 'EmailAddress2' => $rows[0]['EmailAddress2'] ?? null, + 'Phone' => $rows[0]['Phone'] ?? null, + 'MobilePhone1' => $rows[0]['MobilePhone1'] ?? null, + 'MobilePhone2' => $rows[0]['MobilePhone2'] ?? null, + 'Specialty' => $rows[0]['Specialty'] ?? null, + 'SubSpecialty' => $rows[0]['SubSpecialty'] ?? null, + 'Details' => [] + ]; - foreach ($rows as $row) { - if (!empty($row['ContactDetID'])) { - $contact['Details'][] = [ - 'SiteID' => $row['SiteID'] ?? null, - 'ContactDetID' => $row['ContactDetID'], - 'ContactCode' => $row['ContactCode'] ?? null, - 'ContactEmail' => $row['DetailPhone'] ?? null, - 'OccupationID' => $row['OccupationID'] ?? null, - 'JobTitle' => $row['JobTitle'] ?? null, - 'Department' => $row['Department'] ?? null, - 'ContactStartDate' => $row['ContactStartDate'] ?? null, - 'ContactEndDate' => $row['ContactEndDate'] ?? null - ]; + foreach ($rows as $row) { + if (!empty($row['ContactDetID'])) { + $contact['Details'][] = [ + 'SiteID' => $row['SiteID'] ?? null, + 'ContactDetID' => $row['ContactDetID'], + 'ContactCode' => $row['ContactCode'] ?? null, + 'ContactEmail' => $row['DetailPhone'] ?? null, + 'OccupationID' => $row['OccupationID'] ?? null, + 'JobTitle' => $row['JobTitle'] ?? null, + 'Department' => $row['Department'] ?? null, + 'ContactStartDate' => $row['ContactStartDate'] ?? null, + 'ContactEndDate' => $row['ContactEndDate'] ?? null + ]; + } } } - return $contact; }