get(); $centerPostcodeConstant = $centerPostcodeConstantObject->isEmpty() ? [] : (array)$centerPostcodeConstantObject->first()->value; $postcodeArea = in_array((String)$this->postcode, $centerPostcodeConstant) ? 'CENTER_POSTCODE' : null; $outstationPostcodeConstantObject = SegmentConstant::where('reference', SegmentConstants::OUTSTATION_POSTCODE)->get(); $outstationPostcodeConstant = $outstationPostcodeConstantObject->isEmpty() ? [] : (array)$outstationPostcodeConstantObject->first()->value; in_array((String)$this->postcode, $outstationPostcodeConstant) ? $postcodeArea = 'OUTSTATION_POSTCODE' : null; // 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, 'street_two' => $this->street_two, 'district' => $this->district, 'state' => $this->state, 'postcode' => $this->postcode, 'post_code' => $this->postcode, 'post_code_area' => $postcodeArea, 'country' => $this->country, 'default' => (int) $this->default, 'status' => (int) $this->status, 'contact' => new ContactResource($this->contacts->first()), 'remark' => new RemarkResource($this->remarks->first()), 'type' => $this->type, $this->mergeWhen($this->relationLoaded('owner'), [ 'owner' => $this->when($this->owner instanceof Order, [ 'reference' => $this->owner->reference, 'company_module' => new CompanyModuleResource($this->owner->companyModule), 'address' => new AddressResource($this->owner->addresses()->where('status', '=', ApprovalStatus::APPROVED)->first()) ]) ]) ]; // Merge extra fields into the return array if ($extrafields) { $returnArray = array_merge($returnArray, $extrafields); } return $returnArray; } }