46 lines
1.0 KiB
PHP
46 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Banner extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'judul',
|
|
'deskripsi',
|
|
'gambar',
|
|
'url',
|
|
'aktif',
|
|
'urutan',
|
|
'tanggal_mulai',
|
|
'tanggal_selesai'
|
|
];
|
|
|
|
protected $casts = [
|
|
'aktif' => 'boolean',
|
|
'tanggal_mulai' => 'datetime',
|
|
'tanggal_selesai' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Scope untuk mendapatkan banner yang aktif
|
|
*/
|
|
public function scopeAktif($query)
|
|
{
|
|
return $query->where('aktif', true)
|
|
->where(function ($q) {
|
|
$q->whereNull('tanggal_mulai')
|
|
->orWhere('tanggal_mulai', '<=', now());
|
|
})
|
|
->where(function ($q) {
|
|
$q->whereNull('tanggal_selesai')
|
|
->orWhere('tanggal_selesai', '>=', now());
|
|
})
|
|
->orderBy('urutan');
|
|
}
|
|
}
|