Files
investbrain/app/Models/DailyChange.php
T

64 lines
1.4 KiB
PHP
Raw Normal View History

2024-08-10 13:30:19 -05:00
<?php
2025-01-28 17:33:54 -06:00
declare(strict_types=1);
2024-08-10 13:30:19 -05:00
namespace App\Models;
use App\Traits\HasCompositePrimaryKey;
use Illuminate\Database\Eloquent\Factories\HasFactory;
2025-01-28 17:14:49 -06:00
use Illuminate\Database\Eloquent\Model;
2024-08-10 13:30:19 -05:00
class DailyChange extends Model
{
2025-01-28 17:14:49 -06:00
use HasCompositePrimaryKey, HasFactory;
2024-08-10 13:30:19 -05:00
public $timestamps = false;
protected $primaryKey = ['date', 'portfolio_id'];
protected $table = 'daily_change';
protected $fillable = [
'portfolio_id',
'date',
'total_market_value',
'total_cost_basis',
2024-08-21 20:42:32 -05:00
'total_gain',
'total_dividends_earned',
2024-08-10 13:30:19 -05:00
'realized_gains',
'notes',
];
protected $hidden = [];
protected $casts = [
'date' => 'datetime',
];
2025-01-28 17:14:49 -06:00
2024-08-21 20:42:32 -05:00
public function scopePortfolio($query, $portfolio)
{
return $query->where('portfolio_id', $portfolio);
}
2024-08-28 22:06:47 -05:00
2025-01-28 17:14:49 -06:00
public function scopeMyDailyChanges()
2024-08-28 22:06:47 -05:00
{
return $this->whereHas('portfolio', function ($query) {
$query->whereHas('users', function ($query) {
2024-09-25 20:59:09 -05:00
return $query->where('id', auth()->id());
2024-08-28 22:06:47 -05:00
});
});
}
2025-01-28 17:14:49 -06:00
public function scopeWithoutWishlists($query)
{
return $query->whereHas('portfolio', function ($query) {
$query->where('portfolios.wishlist', 0);
});
}
2025-01-28 17:14:49 -06:00
2024-08-15 21:35:43 -05:00
public function portfolio()
{
return $this->belongsTo(Portfolio::class);
}
2024-08-10 13:30:19 -05:00
}