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. try { $this->auth = app(Guard::class); } catch (Throwable $e) { } } private static function guessModelClass(): string { return preg_replace('/(.+)\\\\Repositories\\\\(.+)Repository$/m', '$1\Models\\\$2', static::class); } public function getOneById($id): ?Model { return $this->model->find($id); } /** @return Collection|array */ public function getByIds(array $ids): Collection { return $this->model->whereIn($this->model->getKeyName(), $ids)->get(); } /** @return Collection|array */ public function getAll(): Collection { return $this->model->all(); } public function getFirstWhere(...$params): ?Model { return $this->model->where(...$params)->first(); } public function getModelClass(): string { return $this->modelClass; } }