Skip to content

Commit

Permalink
Apply limit on DatabaseEngine before applying additional constrai…
Browse files Browse the repository at this point in the history
…nts (#621)

The previous PR broke Laravel Nova implementation on Global Search where we use the following:

```php
App\Models\User::search('Laravel')->tap(fn ($query) => $query->limit(5))->get();
``` 

### Before

Callback using `tap()` take priority over default.

#### After

`limit()` take priority over `tap()` and I would consider this a breaking change.
  • Loading branch information
crynobone authored May 5, 2022
1 parent eede290 commit 7b97c85
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/Engines/DatabaseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ protected function searchModels(Builder $builder, $page = null, $perPage = null)
->when(! $this->getFullTextColumns($builder), function ($query) use ($builder) {
$query->orderBy($builder->model->getKeyName(), 'desc');
})
->take($builder->limit)
->get();
}

Expand All @@ -132,7 +131,7 @@ protected function buildSearchQuery(Builder $builder)
);

return $this->constrainForSoftDeletes(
$builder, $this->addAdditionalConstraints($builder, $query)
$builder, $this->addAdditionalConstraints($builder, $query->take($builder->limit))
);
}

Expand Down

0 comments on commit 7b97c85

Please sign in to comment.