'date:Y-m-d', ]; /** * Get all the transactions for the Sale */ public function transactions(): MorphMany { return $this->morphMany(Transaction::class, 'transactionable'); } protected static function booted() { static::deleting(function ($expense) { $expense->transactions->each(function ($transaction) { // Delete associated ledgers first to trigger any ledger deletion logic if exists $transaction->ledgers->each(function ($ledger) { $ledger->balances()->delete(); // Delete balances associated with ledger $ledger->delete(); }); $transaction->delete(); }); }); } public function branch(): BelongsTo { return $this->belongsTo(Branch::class); } public function accounts(): BelongsToMany { return $this->belongsToMany(Account::class, 'account_expense')->withTimestamps(); } public function getAccountsListAttribute(): string { return $this->accounts->pluck('account')->implode(', '); } }