diff --git a/src/Engines/TypesenseEngine.php b/src/Engines/TypesenseEngine.php index f0ae76ff..0c5e1cba 100644 --- a/src/Engines/TypesenseEngine.php +++ b/src/Engines/TypesenseEngine.php @@ -497,26 +497,17 @@ public function deleteIndex($name) protected function getOrCreateCollectionFromModel($model, bool $indexOperation = true): TypesenseCollection { $method = $indexOperation ? 'indexableAs' : 'searchableAs'; + $collectionName = $model->{$method}(); + $collection = $this->typesense->getCollections()->{$collectionName}; - $collection = $this->typesense->getCollections()->{$model->{$method}()}; - - $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) { - // - } - } + // Determine if the collection exists in Typesense... + try { + $collection->retrieve(); - if ($collectionExists) { - return $this->typesense->getCollections()->{$collectionName}; + // No error means this exists on the server + return $collection; + } catch (TypesenseClientError $e) { + // } $schema = config('scout.typesense.model-settings.'.get_class($model).'.collection-schema') ?? [];