modelClass = $modelClass ?: self::guessModelClass(); $this->model = app($this->modelClass); // This instantiation may fail during a console command if e.g. APP_KEY is empty, // rendering the whole installation failing. attempt(fn () => $this->auth = app(Guard::class), false); } private static function guessModelClass(): string { return preg_replace('/(.+)\\\\Repositories\\\\(.+)Repository$/m', '$1\Models\\\$2', static::class); } /** @return T */ public function getOne($id): Model { return $this->model::query()->findOrFail($id); } /** @return T|null */ public function findOne($id): ?Model { return $this->model::query()->find($id); } /** @return array|Collection */ public function getMany(array $ids, bool $inThatOrder = false): Collection { $models = $this->model::query()->find($ids); return $inThatOrder ? $models->orderByArray($ids) : $models; } /** @return array|Collection */ public function getAll(): Collection { return $this->model::all(); } /** @return T|null */ public function getFirstWhere(...$params): ?Model { return $this->model::query()->firstWhere(...$params); } }