From 7b97c85a80f775b33a49be617cf013b1d8f27e55 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 5 May 2022 21:47:23 +0800 Subject: [PATCH] Apply `limit` on `DatabaseEngine` before applying additional constraints (#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. --- src/Engines/DatabaseEngine.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Engines/DatabaseEngine.php b/src/Engines/DatabaseEngine.php index 2d103ffc..806472a4 100644 --- a/src/Engines/DatabaseEngine.php +++ b/src/Engines/DatabaseEngine.php @@ -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(); } @@ -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)) ); }