Point::class, 'boundary_polygon' => Polygon::class, 'accepted_waste_types' => 'array', 'operating_hours' => 'array', 'capacity_tons' => 'integer', ]; } public function getRouteKeyName(): string { return 'uuid'; } protected static function booted(): void { static::creating(function (self $d): void { if (empty($d->uuid)) { $d->uuid = (string) Str::uuid(); } }); } public function cityMunicipality(): BelongsTo { return $this->belongsTo(CityMunicipality::class); } public function releases(): HasMany { return $this->hasMany(DumpsiteRelease::class); } /** * Geofence check: is the given (lat, lng) inside this dumpsite's * boundary polygon? Returns false if no boundary is configured. */ public function containsPoint(float $latitude, float $longitude): bool { if (! $this->boundary_polygon) { return false; } $row = DB::selectOne( 'SELECT ST_Contains(boundary_polygon, ST_SRID(POINT(?, ?), 4326)) AS contained FROM dumpsites WHERE id = ? LIMIT 1', [$longitude, $latitude, $this->id], ); return (bool) ($row->contained ?? false); } }