0

I have to set pagination in array result.

Here is my code.

My Controller code

use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;

public function getCVList(){
.
.
.
$jobseeker1 = array_merge($jobseekers, $apps_array);
// in $jobseeker1 there are 6 result.
$jobseeker = $this->paginate($jobseeker1, 3);
return view('frontend.CVList', compact('jobseeker'));
}


public function paginate($items, $perPage, $pageStart = 1) {

    $offSet = ($pageStart * $perPage) - $perPage;

    // Get only the items you need using array_slice
    $itemsForCurrentPage = array_slice($items, $offSet, $perPage, true);

    return new LengthAwarePaginator($itemsForCurrentPage, count($items), $perPage, Paginator::resolveCurrentPage(), array('path' => Paginator::resolveCurrentPath()));
 }

In blade temoplate i used rander() method and thare are also display pagination. But in all page display same record.

Thanks....

1 Answer 1

1

This is because you are not reading the page number clicked in the paginator, you are setting "3" always as the page to display. Try this:

//include the request
use Illuminate\Http\Request;

Now, read the current page:

public function getCVList(Request $request){
    $perPage = 3;

    // read the page number. When page number is not presented, then you 
    // set it as 0
    $page = $request->get('page', 0);
    $page = ($page == 0)? ($page * $perPage) : ($page * $perPage) - $perPage;

    // now, calling the paginator do magic dynamically
    $jobseeker = $this->paginate($jobseeker1, $perPage, $page);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.