Skip to content
This repository was archived by the owner on Jul 31, 2018. It is now read-only.

Commit 52bb0e4

Browse files
committed
Fix undefined getIndex method
1 parent 8628eb1 commit 52bb0e4

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/AlgoliaEloquentTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function _browseFrom($query, $parameters = [], $cursor = null)
7575
$index = null;
7676

7777
if (isset($parameters['index'])) {
78-
$index = $modelHelper->getIndex($parameters['index']);
78+
$index = $modelHelper->getIndices($this, $parameters['index'])[0];
7979
unset($parameters['index']);
8080
} else {
8181
$index = $modelHelper->getIndices($this)[0];
@@ -100,7 +100,7 @@ public function _browse($query, $parameters = [])
100100
$index = null;
101101

102102
if (isset($parameters['index'])) {
103-
$index = $modelHelper->getIndex($parameters['index']);
103+
$index = $modelHelper->getIndices($this, $parameters['index'])[0];
104104
unset($parameters['index']);
105105
} else {
106106
$index = $modelHelper->getIndices($this)[0];
@@ -125,7 +125,7 @@ public function _search($query, $parameters = [])
125125
$index = null;
126126

127127
if (isset($parameters['index'])) {
128-
$index = $modelHelper->getIndex($parameters['index']);
128+
$index = $modelHelper->getIndices($this, $parameters['index'])[0];
129129
unset($parameters['index']);
130130
} else {
131131
$index = $modelHelper->getIndices($this)[0];

src/ModelHelper.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ public function getSlavesSettings(Model $model)
6767
/**
6868
* @return \AlgoliaSearch\Index
6969
*/
70-
public function getIndices(Model $model)
70+
public function getIndices(Model $model, $indexName = null)
7171
{
7272
$indicesName = [];
7373

74-
if (property_exists($model, 'indices') && is_array($model->indices)) {
74+
if ($indexName !== null) {
75+
$indicesName[] = $indexName;
76+
} elseif (property_exists($model, 'indices') && is_array($model->indices)) {
7577
$indicesName = $model->indices;
7678
} else {
7779
$indicesName[] = $this->getIndexName($model);

tests/ModelHelperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public function testGetIndices()
6060
{
6161
$this->assertEquals('model1s', $this->modelHelper->getIndices(new Model1())[0]->indexName);
6262
$this->assertEquals('model5s_testing', $this->modelHelper->getIndices(new Model5())[0]->indexName);
63+
$this->assertEquals('test', $this->modelHelper->getIndices(new Model1(), 'test')[0]->indexName);
64+
$this->assertEquals('test_testing', $this->modelHelper->getIndices(new Model5(), 'test')[0]->indexName);
6365
$this->assertEquals('model4s', $this->modelHelper->getIndices(new Model4())[0]->indexName);
6466

6567
$indices = $this->modelHelper->getIndices(new Model2());

0 commit comments

Comments
 (0)