Promo endpoint that display only products on sale.

This commit is contained in:
Krzysztof Płaczek
2024-10-18 11:24:46 +02:00
parent 53b6d33ab9
commit fee7495cfe
6 changed files with 69 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ namespace Krzysiej\RyobiCrawler\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* @property integer $skuID
@@ -28,6 +29,11 @@ class Product extends Model
{
return $this->hasMany(Price::class);
}
public function currentPrice(): HasOne
{
return $this->hasOne(Price::class)->latestOfMany('created_at');
}
public function stock(): HasMany
{
return $this->hasMany(Stock::class);