protonemedia / laravel-cross-eloquent-search

Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.
https://protone.media/blog/search-through-multiple-eloquent-models-with-our-latest-laravel-package
MIT License
1.1k stars 80 forks source link

duplicate result in pagination #55

Closed SidneySaints closed 2 years ago

SidneySaints commented 2 years ago

hi,

if i call the paginate or simplePaginate method some results seem to appear again and again on different pages. Currently I cannot find the cause of the problem. Does anyone else have this problem?

Or am i doing something wrong?

My function at my data repository

 public function testCasesSearch(string $result = null, Carbon $from = null, Carbon $to = null): Searcher
    {
        $query = $result ? $this->testCases()->where('result', $result) : $this->testCases();
        return Search::add($query, ['first_name', 'last_name', 'result', 'email', 'phone']);
    }

The Controller

public function testCases(
        CompanyCollection $company,
        Request $request
    ): JsonResponse
    {

        return response()->json(
            $company->testCasesSearch($request->get('result'))
                ->paginate(15, 'page', $request->get('page'))
                ->get($request->get('term'))
        );
    }
pascalbaljet commented 2 years ago

The updated_at column probably contains a lot of equal values, which may cause inconsistent ordering. See also https://github.com/protonemedia/laravel-cross-eloquent-search/issues/47#issuecomment-1025591817