From 1301e7409d6252b6dcdcb0533d7e21157e10f387 Mon Sep 17 00:00:00 2001 From: Will Taylor-Jackson Date: Sun, 27 Jan 2019 13:28:51 +0000 Subject: [PATCH] refactor: toSearchableArray now sets search connection --- src/Collection.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Collection.php b/src/Collection.php index a6cea43..fd5712a 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -13,17 +13,17 @@ public function addToIndex() } $instance = $this->first(); + $instance->setConnection($instance->getElasticsearchConnectionName()); + $query = $this->first()->newQueryWithoutScopes(); - return $instance->onSearchConnection(function ($instance) { - $docs = $this->map(function ($model) { - return $model->onSearchConnection(function ($model) { - return $model->toSearchableArray(); - }, $model); - }); + $docs = $this->map(function ($model, $i) { + return $model->toSearchableArray(); + }); - $query = $instance->newQueryWithoutScopes(); + $success = $query->insert($docs->all()); - return $query->insert($docs->all()); - }, $instance); + unset($docs); + + return $success; } }