65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Spatie\Translatable\HasTranslations;
|
|
|
|
class Slider extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasTranslations;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'label',
|
|
'slug',
|
|
'commentaire',
|
|
'published'
|
|
];
|
|
|
|
/**
|
|
* The attributes that are translatable.
|
|
*
|
|
* @var array
|
|
*/
|
|
public $translatable = [
|
|
'label',
|
|
'slug',
|
|
'commentaire'
|
|
];
|
|
|
|
/**
|
|
* HasMany slides relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function slides()
|
|
{
|
|
return $this->hasMany(Slide::class, 'slider_id')->orderBy('order', 'ASC');
|
|
}
|
|
|
|
/**
|
|
* HasMany showable slides relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
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');
|
|
});
|
|
}
|
|
}
|