|
@@ -3,9 +3,12 @@
|
|
|
namespace App\Services\History\Converter;
|
|
|
|
|
|
use App\Models\User;
|
|
|
+use Illuminate\Support\Collection;
|
|
|
|
|
|
class WhitelistConverter extends EagerLoadingConverter implements ConverterContact
|
|
|
{
|
|
|
+ protected static Collection $items;
|
|
|
+
|
|
|
public function handle(mixed $value)
|
|
|
{
|
|
|
$ids = array_filter(explode(",", $value));
|
|
@@ -14,13 +17,25 @@ class WhitelistConverter extends EagerLoadingConverter implements ConverterConta
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- $users = User::query()->whereIn("id", $ids)->pluck("name");
|
|
|
+ $names = [];
|
|
|
+ foreach ($ids as $id) {
|
|
|
+ if (self::$items->has($id)) {
|
|
|
+ $names[] = self::$items->get($id);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return $users ? implode(",", $users->toArray()) : null;
|
|
|
+ return implode(",", $names);
|
|
|
}
|
|
|
|
|
|
public static function eagerLoad(array $items): void
|
|
|
{
|
|
|
+ $ids = [];
|
|
|
+ foreach ($items as $item) {
|
|
|
+ $ids = [...$ids, ...array_filter(explode(",", $item))];
|
|
|
+ }
|
|
|
+
|
|
|
+ $ids = array_unique(array_filter($ids));
|
|
|
|
|
|
+ self::$items = User::query()->whereIn("id", $ids)->pluck("name", "id");
|
|
|
}
|
|
|
}
|