58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class StabileServizio extends Model
|
|
{
|
|
protected $table = 'stabile_servizi';
|
|
|
|
protected $fillable = [
|
|
'stabile_id',
|
|
'tipo',
|
|
'nome',
|
|
'fornitore_id',
|
|
'voce_spesa_id',
|
|
'documento_collegato_id',
|
|
'codice_utenza',
|
|
'codice_cliente',
|
|
'codice_contratto',
|
|
'contatore_matricola',
|
|
'attivo',
|
|
'meta',
|
|
];
|
|
|
|
protected $casts = [
|
|
'attivo' => 'boolean',
|
|
'meta' => 'array',
|
|
];
|
|
|
|
public function stabile(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Stabile::class, 'stabile_id');
|
|
}
|
|
|
|
public function fornitore(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Fornitore::class, 'fornitore_id');
|
|
}
|
|
|
|
public function voceSpesa(): BelongsTo
|
|
{
|
|
return $this->belongsTo(VoceSpesa::class, 'voce_spesa_id');
|
|
}
|
|
|
|
public function documentoCollegato(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DocumentoCollegato::class, 'documento_collegato_id');
|
|
}
|
|
|
|
public function letture(): HasMany
|
|
{
|
|
return $this->hasMany(StabileServizioLettura::class, 'stabile_servizio_id')->orderByDesc('periodo_al')->orderByDesc('id');
|
|
}
|
|
}
|