dev-major's avatar

How to get unique items from $result_description but pagination?

$result_description = array();

foreach($keywords as $keyword){

        $Candidate =Candidate::where('description','LIKE', "%{$keyword}%")
                        ->orWhereHas('industry', function ($q)use ($keyword) {
                                $q->where('name','LIKE', "%{$keyword}%"); // or email <> ''
                            })
                        ->orWhereHas('experiences', function ($q)use ($keyword) {
                                $q->where('job_title','LIKE', "%{$keyword}%"); // or email <> ''
                            })
                            ->paginate(10);

                            



        $result_description[]=$Candidate;

    }

Result is

array:2 [▼ 0 => LengthAwarePaginator {#794 ▶} 1 => LengthAwarePaginator {#799 ▶} ]

how to merge these record and get unique items

0 likes
1 reply
sujancse's avatar

Why not do like

$Candidate =Candidate::where('description','LIKE', "%{$keyword}%")
            ->orWhereHas('industry', function ($q)use ($keyword) {
                $q->where('name','LIKE', "%{$keyword}%"); // or email <> ''
                $q->orWhere('email', $keyword); // newly added
            })
            ->orWhereHas('experiences', function ($q)use ($keyword) {
                $q->where('job_title','LIKE', "%{$keyword}%"); // or email <> ''
                $q->orWhere('email', $keyword);  // newly added
            })
            ->paginate(10);

you will have your results filtered by name as well as email

Please or to participate in this conversation.