'float', 'longitude' => 'float', 'altitude' => 'float', 'meta' => 'object', ]; /* |-------------------------------------------------------------------------- | Constructor — configurable table name |-------------------------------------------------------------------------- */ public function __construct(array $attributes = []) { parent::__construct($attributes); $this->table = config('addresses.table_names.addresses') ?: parent::getTable(); } /* |-------------------------------------------------------------------------- | Relationships |-------------------------------------------------------------------------- */ /** * All links that reference this address (polymorphic pivot rows). * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function links() { return $this->hasMany( config('addresses.models.address_link', AddressLink::class), 'address_id' ); } /* |-------------------------------------------------------------------------- | Helpers |-------------------------------------------------------------------------- */ /** * Whether the address has geographic coordinates set. */ public function hasCoordinates(): bool { return $this->latitude !== null && $this->longitude !== null; } /** * Whether the address has altitude (AMSL) set. */ public function hasAltitude(): bool { return $this->altitude !== null; } /** * Build a single-line formatted representation of the address. * * Useful for display purposes — joins non-empty components with ", ". */ public function getFormattedAttribute(): string { return collect([ $this->street, $this->street_extra, $this->building ? "({$this->building})" : null, $this->floor ? "Floor {$this->floor}" : null, $this->room ? "Room {$this->room}" : null, $this->postal_code, $this->city, $this->state, $this->county, $this->country_code, ])->filter()->implode(', '); } /** * Return coordinates as an associative array. * * @return array{latitude: float|null, longitude: float|null, altitude: float|null} */ public function toCoordinates(): array { return [ 'latitude' => $this->latitude, 'longitude' => $this->longitude, 'altitude' => $this->altitude, ]; } }