12345678910111213141516171819202122232425262728293031 |
- <?php
- namespace App\Services\History\Converter;
- use App\Models\User;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Collection;
- abstract class ModelConverter extends EagerLoadingConverter implements ConverterContact
- {
- protected static Collection $items;
- protected static string $pluckField = "name";
- protected static string $modelClassName;
- public function handle(mixed $value)
- {
- if (! $value) {
- return null;
- }
- return static::$items?->has($value) ? static::$items?->get($value) : null;
- }
- public static function eagerLoad(array $items): void
- {
- self::$items = app(static::$modelClassName)->whereIn("id", $items)->pluck(static::$pluckField, "id");
- }
- }
|