bega updates

This commit is contained in:
Mekan1206
2026-07-21 21:30:27 +05:00
parent 6093a45761
commit db94922e9a
22 changed files with 1033 additions and 26 deletions

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Models\CMS\Marketing;
use App\Models\Ecommerce\Product\Product\Product;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Spatie\Translatable\HasTranslations;
class FlashSale extends Model
{
use HasFactory;
use HasTranslations;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'id',
'title',
'starts_at',
'ends_at',
'is_visible',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'starts_at' => 'datetime',
'ends_at' => 'datetime',
'is_visible' => 'boolean',
];
/**
* Translatable attributes.
*
* @var array<string>
*/
public $translatable = ['title'];
/**
* Related products.
*/
public function products(): BelongsToMany
{
return $this->belongsToMany(Product::class)
->withTimestamps();
}
/**
* Active flash sales are visible and inside their timer window.
*/
public function scopeActive(Builder $query): Builder
{
return $query
->where('is_visible', true)
->where('starts_at', '<=', now())
->where('ends_at', '>', now());
}
}