feat: announcement

This commit is contained in:
2026-06-24 17:52:59 +03:30
parent b24af706a0
commit 40b7efac2f
4 changed files with 167 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Announcement extends Model
{
protected $fillable = [
'image_id', 'title', 'description', 'link', 'start_date', 'end_date',
];
protected $casts = [
'start_date' => 'datetime',
'end_date' => 'datetime',
];
public function image(): BelongsTo
{
return $this->belongsTo(Image::class);
}
// Currently within its [start_date, end_date] window (null bounds = open-ended).
public function scopeActive($query)
{
$now = now();
return $query
->where(fn ($q) => $q->whereNull('start_date')->orWhere('start_date', '<=', $now))
->where(fn ($q) => $q->whereNull('end_date')->orWhere('end_date', '>=', $now));
}
}