53 lines
1.1 KiB
PHP
Executable File
53 lines
1.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class TipoUtilizzo extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $table = 'tipi_utilizzo';
|
|
|
|
protected $fillable = [
|
|
'codice',
|
|
'descrizione',
|
|
'note',
|
|
'attivo',
|
|
'configurazioni_default'
|
|
];
|
|
|
|
protected $casts = [
|
|
'attivo' => 'boolean',
|
|
'configurazioni_default' => 'array'
|
|
];
|
|
|
|
/**
|
|
* Unità immobiliari con questo tipo di utilizzo
|
|
*/
|
|
public function unitaImmobiliari(): HasMany
|
|
{
|
|
return $this->hasMany(UnitaImmobiliare::class, 'tipo_utilizzo_id');
|
|
}
|
|
|
|
/**
|
|
* Scope per tipi attivi
|
|
*/
|
|
public function scopeAttivi($query)
|
|
{
|
|
return $query->where('attivo', true);
|
|
}
|
|
|
|
/**
|
|
* Ottiene la configurazione default per un campo specifico
|
|
*/
|
|
public function getConfigurazioneDefault(string $campo, $default = null)
|
|
{
|
|
return $this->configurazioni_default[$campo] ?? $default;
|
|
}
|
|
}
|