Fix Corporate Member
This commit is contained in:
@@ -29,6 +29,14 @@ class CorporatePolicy extends Model
|
||||
'active',
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'latestLimitJournal'
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'limit_balance'
|
||||
];
|
||||
|
||||
public function corporate()
|
||||
{
|
||||
return $this->belongsTo(Corporate::class);
|
||||
@@ -39,6 +47,11 @@ class CorporatePolicy extends Model
|
||||
return $this->morphMany(LimitJournal::class, 'journalable');
|
||||
}
|
||||
|
||||
public function latestLimitJournal()
|
||||
{
|
||||
return $this->morphOne(LimitJournal::class, 'journalable')->latestOfMany();
|
||||
}
|
||||
|
||||
public function setCodeAttribute($value)
|
||||
{
|
||||
$this->attributes['code'] = !empty($value) ? $value : Str::upper(Str::random('6'));
|
||||
@@ -61,7 +74,7 @@ class CorporatePolicy extends Model
|
||||
|
||||
public function getLimitBalanceAttribute()
|
||||
{
|
||||
$journal = $this->limitJournals()->latest()->first();
|
||||
$journal = $this->latestLimitJournal;
|
||||
|
||||
return $journal ? $journal->balance : (!empty($this->total_premi) ? $this->total_premi : "0");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user