EmailConverter.php 759 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Services\History\Converter;
  3. use App\Models\User;
  4. use Illuminate\Support\Collection;
  5. class EmailConverter extends EagerLoadingConverter implements ConverterContact
  6. {
  7. protected static Collection $items;
  8. public function handle(mixed $value)
  9. {
  10. if (! $value) {
  11. return null;
  12. }
  13. $items = json_decode($value, true);
  14. $names = [];
  15. foreach ($items as $item) {
  16. if (self::$items?->has($item)) {
  17. $names[] = self::$items?->get($item);
  18. }
  19. }
  20. return implode(",", $names);
  21. }
  22. public static function eagerLoad(array $items): void
  23. {
  24. self::$items = User::query()->whereIn("id", $items)->pluck("name", "id");
  25. }
  26. }