address extra fields

This commit is contained in:
edmondlang
2024-10-14 14:16:33 +08:00
parent 7b0e271459
commit f44497e50c
10 changed files with 151 additions and 31 deletions
+12 -1
View File
@@ -27,7 +27,11 @@ class AddressResource extends JsonResource
$outstationPostcodeConstant = $outstationPostcodeConstantObject->isEmpty() ? [] : (array)$outstationPostcodeConstantObject->first()->value;
in_array((String)$this->postcode, $outstationPostcodeConstant) ? $postcodeArea = 'OUTSTATION_POSTCODE' : null;
return [
// Handle extra fields
$extrafields = $this->addressExtraFields->first();
$extrafields = $extrafields ? json_decode($extrafields->content, true) : [];
$returnArray = [
'id' => $this->id,
'reference' => $this->reference,
'street_one' => $this->street_one,
@@ -52,5 +56,12 @@ class AddressResource extends JsonResource
])
];
// Merge extra fields into the return array
if ($extrafields) {
$returnArray = array_merge($returnArray, $extrafields);
}
return $returnArray;
}
}