Files
MKM/app/Models/Transaction.php
2024-08-15 20:11:21 +08:00

51 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class Transaction extends Model
{
use HasFactory;
protected $guarded = [];
public function transactionable(): MorphTo
{
return $this->morphTo();
}
/**
* Get the account that owns the Transaction
*/
public function account(): BelongsTo
{
return $this->belongsTo(Account::class);
}
public function getAccountTypeAttribute(): string
{
return $this->account->type;
}
/**
* Get the ledgers associated with the Transaction
*
* @return HasOne
*/
public function ledgers(): HasMany
{
return $this->hasMany(Ledger::class);
}
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class);
}
}