diff --git a/src/DesignMyNight/Elasticsearch/Collection.php b/src/DesignMyNight/Elasticsearch/Collection.php new file mode 100644 index 0000000..8cb314f --- /dev/null +++ b/src/DesignMyNight/Elasticsearch/Collection.php @@ -0,0 +1,27 @@ +isEmpty() ){ + return; + } + + $instance = $this->first(); + + $docs = $this->map(function($model){ + return $model->toSearchableArray(); + }); + + return $instance->onSearchConnection(function($docs, $instance){ + $query = $instance->newQueryWithoutScopes(); + + return $query->insert($docs->all()); + }, $docs, $instance); + } +} \ No newline at end of file diff --git a/src/DesignMyNight/Elasticsearch/Searchable.php b/src/DesignMyNight/Elasticsearch/Searchable.php index 2fd5144..4f8a63a 100644 --- a/src/DesignMyNight/Elasticsearch/Searchable.php +++ b/src/DesignMyNight/Elasticsearch/Searchable.php @@ -3,24 +3,6 @@ namespace DesignMyNight\Elasticsearch; trait Searchable { - /** - * The Elasticsearch index this model should be added to - * @var string - */ - protected $searchIndex; - - /** - * The type of document this should be added as - * @var string - */ - protected $searchType; - - /** - * A list of embedded fields that should be indexed as child documents - * @var array - */ - protected $indexAsChildDocuments; - /** * Get the index this model is to be added to *