diff --git a/src/Engines/CollectionEngine.php b/src/Engines/CollectionEngine.php index edd5528b..ca84daa2 100644 --- a/src/Engines/CollectionEngine.php +++ b/src/Engines/CollectionEngine.php @@ -164,10 +164,10 @@ protected function ensureSoftDeletesAreHandled($builder, $query) */ public function mapIds($results) { - $results = $results['results']; + $results = array_values($results['results']); return count($results) > 0 - ? collect($results)->pluck($results[0]->getKeyName())->values() + ? collect($results)->pluck($results[0]->getKeyName()) : collect(); } diff --git a/tests/Feature/CollectionEngineTest.php b/tests/Feature/CollectionEngineTest.php index 48e6710b..14653cef 100644 --- a/tests/Feature/CollectionEngineTest.php +++ b/tests/Feature/CollectionEngineTest.php @@ -101,6 +101,17 @@ public function test_it_can_paginate_results() $models = SearchableUserModel::search('laravel')->paginate(); $this->assertCount(2, $models); + + $dummyQuery = function ($query) { + $query->where('name', '!=', 'Dummy'); + }; + $models = SearchableUserModel::search('laravel')->query($dummyQuery)->orderBy('name')->paginate(1, 'page', 1); + $this->assertCount(1, $models); + $this->assertEquals('Abigail Otwell', $models[0]->name); + + $models = SearchableUserModel::search('laravel')->query($dummyQuery)->orderBy('name')->paginate(1, 'page', 2); + $this->assertCount(1, $models); + $this->assertEquals('Taylor Otwell', $models[0]->name); } public function test_limit_is_applied()