ldc-doux/app/Traits/CastsEnumsHasTranslations.php

50 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Traits;
use Kwaadpepper\Enum\Traits\CastsEnums;
use Spatie\Translatable\HasTranslations;
2022-07-27 14:33:56 +02:00
trait CastsEnumsHasTranslations
{
use CastsEnums, HasTranslations {
CastsEnums::getAttributeValue as enumGetAttributeValue;
CastsEnums::setAttribute as enumSetAttribute;
HasTranslations::getAttributeValue as transGetAttributeValue;
HasTranslations::setAttribute as transSetAttribute;
}
/**
* Manually mix getAttributeValue from CastsEnums and HasTranslations
2022-08-29 17:23:10 +02:00
*
* @param mixed $key
*
* @return string
*/
public function getAttributeValue($key)
{
if ($this->hasEnumCast($key)) {
2022-08-11 12:34:27 +02:00
return $this->enumGetAttributeValue($key);
}
return $this->transGetAttributeValue($key);
}
/**
* Manually mix setAttribute from CastsEnums and HasTranslations
2022-08-29 17:23:10 +02:00
*
* @param mixed $key
* @param mixed $value
*
* @return mixed
*/
public function setAttribute($key, $value)
{
if ($this->hasEnumCast($key)) {
return $this->enumSetAttribute($key, $value);
2022-07-27 14:33:56 +02:00
}
2022-07-27 14:33:56 +02:00
return $this->transSetAttribute($key, $value);
}
}