- article_category - article - eleveur - eleveurs_sites - survey_response - fos_user - aimant_user - content_ocb - encemoment_fiche - encemoment_strates - gamme - home_slider - home_mini_slider - moment_consommation - pays - type_viande - societe - famille_vente - produit - recipe - menu - produit (update) - pictos - pictosproducts - inco_composition - qrcode - product_slider - recipe Articles - reduction - products reductions - saga - user_favorite_recipe Introduces Enum system caster and trait Html Colors auto cast for HomeSliderPictures and Ranges All migrations struct, data and model traits except HomeSliderPicture Days enum system and HomeSliderPicture migration
75 lines
1.3 KiB
PHP
75 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Casts\HtmlColor;
|
|
use App\Enums\Days;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class HomeSliderPictures extends Model
|
|
{
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'catch_color' => HtmlColor::class,
|
|
'title_color' => HtmlColor::class,
|
|
'link_color' => HtmlColor::class
|
|
];
|
|
|
|
protected $hidden = [
|
|
'id',
|
|
'days',
|
|
'status',
|
|
'created_at',
|
|
'updated_at'
|
|
];
|
|
|
|
/**
|
|
* Check if has a specific day
|
|
*
|
|
* @param Days $day
|
|
* @return boolean
|
|
*/
|
|
public function hasDay(Days $day)
|
|
{
|
|
$this->initDays();
|
|
return $day->has($this->days);
|
|
}
|
|
|
|
/**
|
|
* Add a specific day
|
|
*
|
|
* @param Days $day
|
|
* @return void
|
|
*/
|
|
public function addDay(Days $day)
|
|
{
|
|
$this->initDays();
|
|
$this->days |= $day->value;
|
|
}
|
|
|
|
/**
|
|
* Remove a specific day
|
|
*
|
|
* @param Days $day
|
|
* @return void
|
|
*/
|
|
public function removeDay(Days $day)
|
|
{
|
|
$this->initDays();
|
|
$this->days &= ~$day->value;
|
|
}
|
|
|
|
/**
|
|
* Init Days prop if needed
|
|
*
|
|
* @return void
|
|
*/
|
|
private function initDays()
|
|
{
|
|
$this->days = $this->days ?? 0;
|
|
}
|
|
}
|