Skip to content

Commit

Permalink
Add limit to collection engine (laravel#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
keithbrink authored Jan 7, 2022
1 parent ff1de46 commit 0716725
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Engines/CollectionEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
9 changes: 9 additions & 0 deletions tests/Feature/CollectionEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 0716725

Please sign in to comment.