Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit fcc5857

Browse files
committed
Added relations loading
1 parent daa6e44 commit fcc5857

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ App\MyModel::search('phone')
221221
->get();
222222
```
223223

224+
If you need to load relations you can use the `with` method:
225+
226+
```php
227+
App\MyModel::search('phone')
228+
->with('makers')
229+
->get();
230+
```
231+
224232
In addition to standard functionality the package offers you the possibility to filter data in Elasticsearch without specifying a query string:
225233

226234
```php

src/Builders/FilterBuilder.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class FilterBuilder extends Builder
1111
'must_not' => []
1212
];
1313

14+
public $with;
15+
1416
public function __construct($model, $callback = null)
1517
{
1618
$this->model = $model;
@@ -133,4 +135,11 @@ public function buildPayload()
133135
{
134136
return $this->engine()->buildSearchQueryPayloadCollection($this);
135137
}
138+
139+
public function with($relations)
140+
{
141+
$this->with = $relations;
142+
143+
return $this;
144+
}
136145
}

src/ElasticEngine.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,18 @@ public function getTotalCount($results)
224224
{
225225
return $results['hits']['total'];
226226
}
227+
228+
/**
229+
* @inheritdoc
230+
*/
231+
public function get(Builder $builder)
232+
{
233+
$collection = parent::get($builder);
234+
235+
if (isset($builder->with) && $collection->count() > 0) {
236+
$collection->load($builder->with);
237+
}
238+
239+
return $collection;
240+
}
227241
}

0 commit comments

Comments
 (0)