41 lines
813 B
PHP
41 lines
813 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class TerritorioMappa extends Model
|
|
{
|
|
protected $table = 'territorio_mappe';
|
|
|
|
protected $fillable = [
|
|
'territorio_id',
|
|
'geojson',
|
|
'image_path',
|
|
'rendered_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'rendered_at' => '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;
|
|
}
|
|
}
|