This commit is contained in:
hackerESQ
2024-08-24 22:19:40 -05:00
parent 5e89e66e7b
commit 54cf25aabc
13 changed files with 423 additions and 179 deletions
+18 -10
View File
@@ -14,11 +14,6 @@ class Holding extends Model
protected $with = ['market_data'];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'portfolio_id',
'symbol',
@@ -31,16 +26,29 @@ class Holding extends Model
'dividends_synced_at'
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'splits_synced_at' => 'datetime',
'dividends_synced_at' => 'datetime',
];
protected $appends = [
'market_gain_percent'
];
/**
* Append the market gain / loss percent attribute
*
* @return int
*
*/
public function getMarketGainPercentAttribute()
{
return (int) !empty($this->market_data?->market_value) && !empty($this->average_cost_basis)
? (($this->market_data->market_value - $this->average_cost_basis) / $this->average_cost_basis) * 100
: 0;
}
/**
* Market data for holding
*