diff --git a/src/Engines/CollectionEngine.php b/src/Engines/CollectionEngine.php index 263e90e1..edd5528b 100644 --- a/src/Engines/CollectionEngine.php +++ b/src/Engines/CollectionEngine.php @@ -50,7 +50,7 @@ public function delete($models) */ public function search(Builder $builder) { - $models = $this->searchModels($builder); + $models = $this->searchModels($builder)->take($builder->limit); return [ 'results' => $models->all(), diff --git a/tests/Feature/CollectionEngineTest.php b/tests/Feature/CollectionEngineTest.php index 5b1134d4..48e6710b 100644 --- a/tests/Feature/CollectionEngineTest.php +++ b/tests/Feature/CollectionEngineTest.php @@ -102,4 +102,13 @@ public function test_it_can_paginate_results() $models = SearchableUserModel::search('laravel')->paginate(); $this->assertCount(2, $models); } + + public function test_limit_is_applied() + { + $models = SearchableUserModel::search('laravel')->get(); + $this->assertCount(2, $models); + + $models = SearchableUserModel::search('laravel')->take(1)->get(); + $this->assertCount(1, $models); + } }