Dhruv Sompura's avatar

Laravel Pagination onEachSide is not working

I am fetching users list from database, and i added this code, pagination is working fine but onEachSide is not working

$users = User::paginate(5); {{ $users_list->onEachSide(2)->links() }}

0 likes
7 replies
chaudigv's avatar

Shouldn't it be {{ $users->onEachSide(2)->links() }}?

Dhruv Sompura's avatar

I write users_list because i send data in users_list

return view('admin.users',['users_list'=>$users]);

neilstee's avatar

@dhruv sompura your code looks fine tho assuming $users_list on your blade is the $users in your controller.

But you need to make sure you have enough data or else onEachSide won't work. Try populating 10 users and see if it works.

Dhruv Sompura's avatar

Hey, thank you for response,

I have total 80 records and 10 records per page, still all pages are display.

return $results = DB::table($this->table)->paginate($pagination)->onEachSide(2);

rovshena's avatar

In your controller:

​public function show()
​{
   ​$users = User::paginate(5, ['*'], __('page'))->onEachSide(2);

   ​return view('user-list-view', ['users' => $users]);
​}

In your view:

{{ $users->links() }
Dhruv Sompura's avatar

Thank you for your response, i try this but didnt work for me,

This is my model code

public function all_users($pagination=0) { if($pagination == 0) { return $results = DB::table($this->table)->get(); } else { return $results = DB::table($this->table)->paginate(5)->onEachSide(5); } }

Please or to participate in this conversation.