123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace App\Services\History\Converter;
- use App\Models\CustomField;
- class CustomFieldSelectConverter extends NotEagerLoadingConverter implements ConverterContact
- {
- public function __construct(protected string $group, protected string $field)
- {
- }
- public function handle(mixed $value)
- {
- $customField = CustomField::query()->where("group", $this->group)->where("key", $this->field)->first();
- $relations = [];
- if ($customField?->options) {
- $alias = [
- 'zh_CN' => 'zh',
- ];
- $lang = $alias[config("app.locale")] ?? config("app.locale");
- foreach ($customField->options as $option) {
- $relations[$option['value']] = $option['lang'][$lang] ?? $option['lang']['en'];
- }
- }
- return $relations[$value] ?? $value;
- }
- }
|