46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Casts;
|
|
|
|
use App\Casts\RgbaColor as CastsRgbaColor;
|
|
|
|
/**
|
|
* Custom cast RGBA Color nullable
|
|
* https://laravel.com/docs/8.x/eloquent-mutators#custom-casts
|
|
*/
|
|
class RgbaColorNullable extends CastsRgbaColor
|
|
{
|
|
/**
|
|
* Cast the given value.
|
|
*
|
|
* @param Model $model
|
|
* @param string $key
|
|
* @param mixed $value
|
|
* @param array $attributes
|
|
* @return string
|
|
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
|
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
|
*/
|
|
public function get($model, $key, $value, $attributes)
|
|
{
|
|
// phpcs:enable
|
|
return \is_null($value) ? $value : parent::get($model, $key, $value, $attributes);
|
|
}
|
|
|
|
/**
|
|
* Prepare the given value for storage.
|
|
*
|
|
* @param Model $model
|
|
* @param string $key
|
|
* @param mixed $value
|
|
* @param array $attributes
|
|
* @return integer
|
|
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
|
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
|
*/
|
|
public function set($model, $key, $value, $attributes)
|
|
{
|
|
// phpcs:enable
|
|
return \is_null($value) ? $value : parent::set($model, $key, $value, $attributes);
|
|
}
|
|
}
|