From 11fd53ada64244db503d77243271f97b763b88c4 Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Fri, 26 Sep 2025 10:17:52 +0700 Subject: [PATCH] fix ContactID null on contact_show using data from url --- app/Models/ContactModel.php | 65 +++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/app/Models/ContactModel.php b/app/Models/ContactModel.php index 13b58d3..1364e87 100644 --- a/app/Models/ContactModel.php +++ b/app/Models/ContactModel.php @@ -26,40 +26,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 = []; - 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($contact['NameFirst'])) { + $contact = [ + 'ContactID' => $ContactID, + 'NameFirst' => $row['NameFirst'] ?? null, + 'NameLast' => $row['NameLast'] ?? null, + 'Title' => $row['Title'] ?? null, + 'Initial' => $row['Initial'] ?? null, + 'Birthdate' => $row['Birthdate'] ?? null, + 'EmailAddress1' => $row['EmailAddress1'] ?? null, + 'EmailAddress2' => $row['EmailAddress2'] ?? null, + 'Phone' => $row['Phone'] ?? null, + 'MobilePhone1' => $row['MobilePhone1'] ?? null, + 'MobilePhone2' => $row['MobilePhone2'] ?? null, + 'Specialty' => $row['Specialty'] ?? null, + 'SubSpecialty' => $row['SubSpecialty'] ?? null, + 'Details' => [] + ]; + } + 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; }