31 lines
802 B
PHP
31 lines
802 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Slider extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public function slides()
|
|
{
|
|
return $this->hasMany(Slide::class, 'slider_id')->orderBy('order', 'ASC');
|
|
}
|
|
|
|
public function showableSlides()
|
|
{
|
|
$now = Carbon::now();
|
|
return $this->hasMany(Slide::class, 'slider_id')
|
|
->orderBy('order', 'ASC')->where(function ($q) use ($now) {
|
|
$q->whereDate('date_start', '<=', $now)
|
|
->orWhereNull('date_start');
|
|
})->where(function ($q) use ($now) {
|
|
$q->whereDate('date_end', '>=', $now)
|
|
->orWhereNull('date_end');
|
|
});
|
|
|
|
}
|
|
}
|