diff --git a/src/Engines/TypesenseEngine.php b/src/Engines/TypesenseEngine.php index 835aac83..7060ac01 100644 --- a/src/Engines/TypesenseEngine.php +++ b/src/Engines/TypesenseEngine.php @@ -500,8 +500,23 @@ protected function getOrCreateCollectionFromModel($model, bool $indexOperation = $collection = $this->typesense->getCollections()->{$model->{$method}()}; - if ($collection->exists() === true) { - return $collection; + $collectionExists = false; + + if ($collection->exists()) { + // Also determine if the collection exists in Typesense... + $collectionName = $model->{$method}(); + + try { + $this->typesense->collections[$collectionName]->retrieve(); + + $collectionExists = true; + } catch (TypesenseClientError $e) { + // + } + } + + if ($collectionExists) { + return $this->typesense->getCollections()->{$collectionName}; } $schema = config('scout.typesense.model-settings.'.get_class($model).'.collection-schema') ?? [];