'datetime', ]; } public function territorio() { return $this->belongsTo(Territorio::class, 'territorio_id'); } /** * La geometria decodificata (Polygon/MultiPolygon GeoJSON) o null se * il contenuto non è più interpretabile. */ public function geometria(): ?array { $decoded = json_decode($this->geojson, true); return is_array($decoded) ? $decoded : null; } /** Se è collegata a un territorio, il PDF si può generare. */ public function collegata(): bool { return $this->territorio_id !== null && $this->territorio !== null; } /** * Come si chiama questa piantina nell'interfaccia: il numero del * territorio se c'è, altrimenti il nome scelto a mano, altrimenti un * ripiego che almeno la distingue dalle altre. */ public function etichetta(): string { if ($this->collegata()) { return 'Terr. ' . $this->territorio->numero; } $nome = trim((string) $this->nome); return $nome !== '' ? $nome : 'Piantina #' . $this->id; } }