belongsTo(Account::class); } /** * Get the Weather record associated with the place. * * @return HasMany */ public function weathers() { return $this->hasMany(Weather::class); } /** * Get the address as a sentence. * * @return string|null */ public function getAddressAsString(): ?string { $address = ''; if (! is_null($this->street)) { $address = $this->street; } if (! is_null($this->city)) { $address .= ' '.$this->city; } if (! is_null($this->province)) { $address .= ' '.$this->province; } if (! is_null($this->postal_code)) { $address .= ' '.$this->postal_code; } if (! is_null($this->country)) { $address .= ' '.$this->getCountryName(); } if (empty($address)) { return null; } // trim extra whitespaces inside the address $address = preg_replace('/\s+/', ' ', $address); if (is_string($address)) { return $address; } return null; } /** * Get the country of the place. * * @return string|null */ public function getCountryName(): ?string { if ($this->country) { return CountriesHelper::get($this->country); } return null; } /** * Get an URL for Google Maps for the place. * * @return string */ public function getGoogleMapAddress() { $place = $this->getAddressAsString(); $place = urlencode($place); return "https://www.google.com/maps/place/{$place}"; } /** * Get the Google Maps url for the latitude/longitude. * * @return string */ public function getGoogleMapsAddressWithLatitude() { return 'http://maps.google.com/maps?q='.$this->latitude.','.+$this->longitude; } }