| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App;
- use Exception;
- /**
- * Class Address
- * @property int $id
- * @property string $address_1
- * @property string $address_2
- * @property string $city
- * @property string $county
- * @property string $postal_code
- * @property string $state
- * @property string $country
- * @property float $latitude
- * @property float $longitude
- */
- class Address extends Model {
- protected static $table = "address";
- protected static $idField = "id";
- protected static $fillableFields = ["address_1", "address_2", "city", "county", "postal_code", "state", "country", "latitude", "longitude"];
- // Static methods
- public static function getCountryOptions(): array {
- return [
- "FR" => __("France"),
- "DE" => __("Germany"),
- "JP" => __("Japan"),
- "ES" => __("Spain"),
- "GB" => __("United Kingdom"),
- ];
- }
- // Object methods
- public function hasGeolocation(): bool {
- return isset($this->latitude, $this->longitude);
- }
- public function geocode(): ?array {
- try {
- $results = Geolocation::geocode($this->postal_code);
- $result = $results[0];
- $this->latitude = $result->geometry->location->lat;
- $this->longitude = $result->geometry->location->lng;
- return [$this->latitude, $this->longitude];
- }
- catch(Exception $e) {
- return null;
- }
- }
- }
|