| Current Path : /var/www/html/LLCF-APP/app/Models/ |
| Current File : /var/www/html/LLCF-APP/app/Models/BankAccount.php |
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class BankAccount extends Model
{
use HasFactory;
protected $table = 'bank_accounts';
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'account_type',
'account_name',
'account_number',
'bank_name',
'currency',
'address',
'from_date',
'to_date',
'opening_balance',
'closing_balance',
];
/**
* The attributes that should be cast to native types.
*/
protected $casts = [
'from_date' => 'date',
'to_date' => 'date',
'opening_balance' => 'decimal:2',
'closing_balance' => 'decimal:2',
];
/**
* Get all transactions associated with this account.
*/
public function transactions()
{
return $this->hasMany(BankTransaction::class, 'bank_account_id');
}
/**
* Scope for filtering by account type.
*/
public function scopeOfType($query, $type)
{
return $query->where('account_type', $type);
}
/**
* Helper accessor for formatted account display name.
*/
public function getDisplayNameAttribute(): string
{
return "{$this->account_name} ({$this->account_number}) " . ucfirst($this->account_type);
}
}