- 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
40 lines
920 B
PHP
40 lines
920 B
PHP
<?php
|
|
|
|
namespace App\Casts;
|
|
|
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
|
|
|
/**
|
|
* Custom cast Html Color
|
|
* https://laravel.com/docs/8.x/eloquent-mutators#custom-casts
|
|
*/
|
|
class HtmlColor implements CastsAttributes
|
|
{
|
|
/**
|
|
* Cast the given value.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Model $model
|
|
* @param string $key
|
|
* @param mixed $value
|
|
* @param array $attributes
|
|
* @return string
|
|
*/
|
|
public function get($model, $key, $value, $attributes)
|
|
{
|
|
return dechex($value);
|
|
}
|
|
|
|
/**
|
|
* Prepare the given value for storage.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Model $model
|
|
* @param string $key
|
|
* @param array $value
|
|
* @param array $attributes
|
|
* @return int
|
|
*/
|
|
public function set($model, $key, $value, $attributes)
|
|
{
|
|
return \intval(hexdec(ltrim($value, '#')));
|
|
}
|
|
}
|