<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Conto extends Model
{
    use HasFactory;

    protected $fillable = [
        'nomeConto',
        'Banca',
        'IBAN',
        'saldo_iniziale',
        'note',
    ];

    public function movimenti()
    {
        return $this->hasMany(Movimenti::class);
    }

    public function saldo()
    {
        return $this->saldo_iniziale + $this->movimenti()->sum('importo');
    }
}
// Compare this snippet from app/Models/Movimenti.php: