[silindi]
app/ProductPrice.php:
public function scopeByLastWeek($query)
{
return $query->whereBetween('created_at', [
now()->subWeek()->startOfWeek(),
now()->subWeek()->endOfWeek(),
]);
}
public function scopeByLastMonth($query)
{
return $query->whereBetween('created_at', [
now()->subMonth()->startOfMonth(),
now()->subMonth()->endOfMonth(),
]);
}
$product = Product::find(1);
$lastMonthPrices = $product->prices()
->byLastMonth()
->get();