Files
investbrain/app/Models/DailyChange.php
T
hackerESQ 58533a454d wip
2024-08-21 20:42:32 -05:00

76 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use App\Traits\HasCompositePrimaryKey;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class DailyChange extends Model
{
use HasFactory, HasCompositePrimaryKey;
public $timestamps = false;
/**
* The primary key of the table.
*
* @var string
*/
protected $primaryKey = ['date', 'portfolio_id'];
/**
* Table name for the model
*
* @var string
*/
protected $table = 'daily_change';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'portfolio_id',
'date',
'total_market_value',
'total_cost_basis',
'total_gain',
'total_dividends_earned',
'realized_gains',
'notes',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'date' => 'datetime',
];
public function scopeMyDailyChanges($query)
{
return $query->where('user_id', auth()->user()->id);
}
public function scopePortfolio($query, $portfolio)
{
return $query->where('portfolio_id', $portfolio);
}
public function portfolio()
{
return $this->belongsTo(Portfolio::class);
}
}