ldc-mesbr-app/app/Models/Calendrier.php
2026-10-28 17:35:34 +01:00

63 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
class Calendrier extends Model
{
/**
* @var string
*/
protected $table = 'calendrier';
/**
* @var boolean
*/
public $timestamps = false;
/**
* @var string
*/
protected $primaryKey = 'calendrier_id';
protected $dates = ['calendrier_startdate', 'calendrier_enddate'];
/**
* @var array
*/
protected $fillable = [
'calendrier_startdate',
'calendrier_enddate'
];
/**
* ManyToOne
* Calendrier -> Coupon
*/
public function coupon()
{
return $this->belongsTo(\App\Models\Coupon::class, 'calendrier_couponId');
}
// * METHODS
/**
* Check if the current date is between the calendar publication dates.
*
* @return boolean
*/
public function isPublished(): bool
{
return now()->betweenIncluded(
Carbon::parse($this->calendrier_startdate),
Carbon::parse($this->calendrier_enddate)->endOfDay()
);
}
}