feat: enhance address handling with coordinates and integrate into event resources

This commit is contained in:
2026-09-30 10:59:41 -03:00
parent 5d5ee7d2a5
commit 6588d9f1a8
13 changed files with 282 additions and 8 deletions

View File

@@ -20,6 +20,16 @@ class Address extends Model
];
}
/** @return array{latitude: float, longitude: float}|null */
public function coordinates(): ?array
{
if ($this->latitude === null || $this->longitude === null) {
return null;
}
return ['latitude' => (float) $this->latitude, 'longitude' => (float) $this->longitude];
}
/** @return HasMany<Event, $this> */
public function events(): HasMany
{

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Domains\Core\Address\Resources;
use App\Domains\Core\Address\Models\Address;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin Address */
class AddressResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'label' => $this->label,
'address_text' => $this->address_text,
'latitude' => $this->latitude === null ? null : (float) $this->latitude,
'longitude' => $this->longitude === null ? null : (float) $this->longitude,
];
}
}