Browse AI Field GuideForum Podcast
All ThreadsLeaderboard
  1. Discussions

    1. Popular This Week
    2. Popular All Time
    3. Solved
    4. Unsolved
    5. No Replies Yet

davidlm75's avatar

Pagination and column sorting

I'm trying to use pagination and sort the columns on each page. It doesn't sort just the 10 records retrieved, but the entire table. When I change the page it loses the sort order and goes back to the default. public function index() { if(Auth::check()) { $sortby = Input::get('sortby'); $order = Input::get('order'); if($sort

davidlm75's avatar
davidlm75's avatar davidlm7511yrs agoGeneral
12
1
Last reply by davidlm75 11yrs ago
yuriikrevnyi's avatar

How to mock pagination

Hi! I am trying to mock my pagination. Here I have PostsRepository and in method all() there is code like this: return $this->_post->paginate(20); How could I test this? In my test I have: $posts = new Collection([new Post, new Post]); $this->_repo->shouldReceive('all')->once()->andReturn($posts); .. and this tests are failing with error: Call to undefined method Illuminate

yuriikrevnyi's avatar
yuriikrevnyi's avatar yuriikrevn...11yrs agoTesting
1
1
Last reply by yuriikrevnyi 11yrs ago
bestmomo's avatar

L5 : Pagination url

Hello, When I test pagination on a fresh Laravel 5 with a simple code : $user = \App\User::paginate(2); dd($user->render()); I get this sort of url : ...public/test/?page=2 There is a slash "/" before the "?" so the url is not correct. Do I miss something ?

bestmomo's avatar
bestmomo's avatar bestmomo10yrs agoGeneral
30
1
Last reply by bestmomo 10yrs ago
Devon's avatar

Previous/Next Record Pagination

I have bunch of entities, we'll call them articles, which are categorized through a pivot table. Currently, I have a category page that shows all of the articles in that category along with pagination at the bottom. However, what I'm trying to accomplish now is; when you're viewing an individual article, I want to have links to the Previous/Next article in the same category.

Devon's avatar
Devon's avatar Devon11yrs agoGeneral
0
1
iocod's avatar

How can i do Laravel pagination for multiple table results(No relations)?.(i need this function to show search results from multiple tables)

$mobiles=Mobile::select('id','name','blurb','priority') ->where('name','LIKE','%'.$key.'%') ->paginate(3); $televisions=Television::select('id','name','blurb','priority') ->where('name','LIKE','%'.$key.'%') ->paginate(3); $washingmachines=Waching::select('id','name','blurb','priority')

iocod's avatar
iocod's avatar ha77an4yrs agoGeneral
11
1
Last reply by ha77an 4yrs ago
Valorin's avatar

L5 Pagination with numbered pages

Has anyone figured out how to use the new pagination with Eloquent models in Laravel 5 to display anything other than the simple version with only next and previous links? I'm upgrading a site and I used to use the numbered page pagination, which is the same as is used here on Laracasts, however I cannot figure out how to do it! It seems like it now involves manually bootstrap

Valorin's avatar
Valorin's avatar Valorin11yrs agoGeneral
1
1
Last reply by Valorin 11yrs ago
ivanhalen's avatar

Laravel Pagination: a new one adapted from an old Dreamweaver extension

I'm new to Laravel and I'm trying to port the most important old-procedural-code snippets and libraries I collect in some years I missed a nice Pagination I had in an old Dreamweaver extension and I tried to replicate it: I asked on Stack Overflow but was unsatisfied, so I decided to play around and convert the Dreamweaver extensions code with a lot of patience. Here is the r

ivanhalen's avatar
ivanhalen's avatar ivanhalen11yrs agoGeneral
0
1
NikkiLoveGod's avatar

Sorting and pagination with repositories

Hi, How would I go about implementing sorting and pagination when I am using repositories? Lets say that I have a method in repository like $this->userRepository->getUsersInGroup($groupId). How do I implement pagination and sorting in that case?

NikkiLoveGod's avatar
NikkiLoveGod's avatar weareworth...9yrs agoGeneral
6
1
Last reply by weareworthers 9yrs ago
cbojer's avatar

Pagination bug with Search

When you search, and there are enough results for it to be paginated, the pagination links don't include the query string. For instance, try to search for "git" and click on page 2. The link is now search?page=2, which redirects to /lessons. It should instead be search?q=git&page=2

cbojer's avatar
cbojer's avatar TravisBlas...11yrs agoFeedback
11
1
Last reply by TravisBlasingame 11yrs ago
GianniGianni's avatar

Custom pagination URL

With the default laravel pagination my url looks like mydomain.com/item?page=2 Is there a way to obtain something like mydomain.com/item/2 or mydomain.com/item/page/2 Thanks :)

GianniGianni's avatar
GianniGianni's avatar kornel6yrs agoRequests
10
1
Last reply by kornel 6yrs ago
DirkZz's avatar

Pagination on the Whats new page

Would it be possible to add a pagination to the "latest video's" page, which can be found here; https://laracasts.com/latest Sometimes I don't visit Laracasts weekly, and I would like to pick things up where I left. Would really like that.

DirkZz's avatar
DirkZz's avatar DirkZz11yrs agoFeedback
3
1
Last reply by DirkZz 11yrs ago
theilen's avatar

Pagination for search results not working

It seems like the pagination for search results is buggy. I search for "forms", scroll down and click on "2". On the next page the url is "https://laracasts.com/discuss?page=2&search=form" and on the bottom of the page the "2" is highlighted. But I see the same results as on the first page.

theilen's avatar
theilen's avatar theilen11yrs agoFeedback
5
1
Last reply by theilen 11yrs ago
SPresnac's avatar

Rerender JavaScript stuff on page after search or pagination

Hej, i do have a list of People that is paginated (by 12, just for saying). Every one has a button right beside the name with a flux:modal (but the problem is the same with other js stuff, just as example). So, on the first page, all works well. But when changing the page or searching someone who was not initially in the list of the first 12, the modal will not open. I am sugge

SPresnac's avatar
SPresnac's avatar SPresnac7mos agoLivewire
3
1
Last reply by SPresnac 7mos ago
danialm's avatar

pagination problem

Hello, I want to display a book. Everything is correct. But I want the comments to be in the form of a paginate. Only the comments. What is the solution? My code: public function show(Book $book) { return $book->load(['categories', 'comments'])->toResource(); } I want the comments to be in the form of a pitch.

danialm's avatar
danialm's avatar Snapey8mos agoEloquent
1
1
Last reply by Snapey 8mos ago
uelh's avatar

Inertia deepMerge, Laravel Resource Collections & Pagination (page=NaN)

Hi all, I’m implementing infinite scroll with Inertia.js (latest), Laravel, and the new deepMerge feature. I’m following the approach from Laracasts Inertia 2 Unleashed, Ep 5, but running into issues. Controller: public function index(Request $request) { $data = $request->all(); $data['user_id'] = auth()->id(); $projects = $this->service->all($data);

uelh's avatar
uelh's avatar uelh1yr agoInertia
0
1
yonka's avatar

laravel livewire pagination links not working in where clause

{ return view('livewire.purchase.index',[ 'purchases' => Purchase::where('user_id',auth()->user()->id)->get(), ]); } in the purchase.index {{ $purchases->links() }} But it shows this error Method Illuminate\Database\Eloquent\Collection::links does not exist.

yonka's avatar
yonka's avatar Snapey1yr agoLaravel
3
1
Last reply by Snapey 1yr ago
sarfaraz1212's avatar

Pagination data not coming in api resource

i want to use api resource in my function function get($id = null,$search = null) { try { $query = User::with('details', 'documents', 'pictures') ->where('id', '!=', 1); if ($id) { return $query->where('id', $id)->firstOrFail(); } if ($search) { $query->whe

sarfaraz1212's avatar
sarfaraz1212's avatar sarfaraz12...1yr agoLaravel
7
1
Last reply by sarfaraz1212 1yr ago
PrinceMinky's avatar

Pagination, Modals and Livewire

Hello, I have run into an issue. I have looped modals for each user that is displayed like so: @foreach ($this->users as $user) <flux:modal name="edit-user-{{ $user->id }}" class="w-full space-y-6"> @include('livewire.admin.user-management.form') </flux:modal> <flux:modal name="delete-profile-{{ $user->id

PrinceMinky's avatar
PrinceMinky's avatar jj151yr agoLivewire
4
1
Last reply by jj15 1yr ago
rhysdev's avatar

Livewire 3 pagination update not longer refreshing elements

Hi guys, got a little issue since upgrading to Livewire 3. I have a page which loops through a bunch of records and uses a script $( document ).ready(function() { for each record to generate the needed chart. Since Livewire 3 the $( document ).ready(function() { no longer works apart from the initial load of the page. Is there another way i should now be using this to re-render

rhysdev's avatar
rhysdev's avatar rhysevansd...1yr agoLivewire
2
1
Last reply by rhysevansdev 1yr ago
t0berius's avatar

pagination() generate relative URLs

Is there a way to make ->paginate() generate relative URLs like /users?page=3 instead of domain.tld/users?page=3. I wasn't able to find anything related inside doc.

t0berius's avatar
t0berius's avatar t0berius1yr agoLaravel
4
1
Last reply by t0berius 1yr ago
Zoul's avatar

Pagination is slow after migrating to livewire3

Hello, It taks like 4 or 5 seconds to render from one page to another, i did cleared cache and used different paginte or simplePaginate in my component but still the same BlogList component use Livewire\Component; use Livewire\WithPagination; use App\Models\Blog; use Hashids\Hashids; class BlogList extends Component { use WithPagination; protected $paginationTheme = 'bo

Zoul's avatar
Zoul's avatar Zoul1yr agoLivewire
0
1
Ligonsker's avatar

A query with pagination takes much longer than using get()

Hello, I was trying to see why a page takes over a minute to load. At first, I thought the query is too complex and unoptimized, so I directly put the raw query (given by ->toSql()) into the Microsoft SQL Server Management Studio. But to my surprise the query executed instantly (00:00:00). But in Laravel it takes over 20 seconds The difference is that in Laravel I use $query

Ligonsker's avatar
Ligonsker's avatar jlrdw2yrs agoLaravel
3
1
Last reply by jlrdw 2yrs ago
abkrim's avatar

Problems implementing pdfphilip/laravel-elasticsearch due to pagination

I am facing a problem, where I cannot use the liberia pdfphilip/laravel-elasticsearch which basically extends the Eloquent model for using Elasticsearch indexes. When I went to implement it I ran into the aggregations (I think) that arise in how Filament builds the model listing. The point is that the package works with a method that allows you not to change the Elastic configu

abkrim's avatar
abkrim's avatar abkrim2yrs agoFilament
3
1
Last reply by abkrim 2yrs ago
Nando7's avatar

Query with pagination slow performance when LESS than 10 records

I am facing slow performance on a paginated query. When it has to fetch less than 10 records, it takes one minute. When its more than 10, it takes half a minute. If it is more than a thousand it takes 5 seconds!!! Yes, the more data it has to fetch, the faster it is!!!!!! The query: $facilities = auth()->user()->facilities; $notSentStatusId = PlacementOpportunityS

Nando7's avatar
Nando7's avatar Nando72yrs agoLaravel
2
1
Last reply by Nando7 2yrs ago
yaddly's avatar

Pagination adding route-parameter to page-links after Model update

Good day Laracons, I am using Route::resources([]) to generate routes, but I realized that I needed the page number from the url query string sent to controller action methods. So, I appended it to the route as query string: href="{{ route('nationalities.edit', ['nationality' => $nationality?->id, 'page' => Request::query('page', 1)]) }}" So, the url for edit

yaddly's avatar
yaddly's avatar yaddly2yrs agoGeneral
15
4
Last reply by yaddly 2yrs ago
rohitjangir's avatar

Pagination is not working ?

@foreach ($category->products as $_product) {{-- {{ $_product->name }} --}} {{ $_product->name }} @if ($_product->special_price) <h5>{{ $_product->special_price }}</h5> <h6 class="text-muted ml-2"><del>

rohitjangir's avatar
rohitjangir's avatar Ben Taylor2yrs agoLaravel
4
1
Last reply by Ben Taylor 2yrs ago
jbeduya's avatar

Cursor pagination - "Illegal operator and value combination."

I have the following component class Index extends Component { use WithPagination; public $query = ''; public function getItems() { return Student::select(['id', 'firstname', 'lastname', 'midname', 'email', 'phone']) ->orderBy('lastname', 'asc')->orderBy('firstname', 'asc')->orderBy('midname', 'asc') ->when(

jbeduya's avatar
jbeduya's avatar jbeduya2yrs agoLivewire
2
1
Last reply by jbeduya 2yrs ago
kuechenplaner's avatar

Pagination with loading relationships is not working

Hello, how can i paginate the "recipes"? If I use paginate, then it paginates the $user and not the "recipes". namespace App\Http\Controllers; use App\Http\Requests\UserProfileRequest; use App\Models\User; use Inertia\Inertia; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class UserProfileController extends Controller { public func

kuechenplaner's avatar
kuechenplaner's avatar Snapey2yrs agoEloquent
2
1
Last reply by Snapey 2yrs ago
eggplantSword's avatar

Simple pagination behaving strangely when changing pages

I'm trying to paginate form.sale_point_routes since they can quite long (400+) but what's happening is that it adds the new items below the current ones and then removes the current ones and leave the new ones so it looks weird. here is a video of what I mean (sorry it expires in 2 days so on 01/27/24) https://streamable.com/rum6ie here is another video with more items that sho

eggplantSword's avatar
eggplantSword's avatar gych2yrs agoVue
1
1
Last reply by gych 2yrs ago
Ligonsker's avatar

How to prevent double queries when I need both pagination and the entire collection?

Hello, I need both paginate for the display but also the entire collection to do some calculations in the backend. Right now I do it straightforward $data = DB::table('table')->where(...)->get(); $paginator = DB::table('table')->where(...)->paginate(); But can I improve it and prevent double queries? WIll I need to create a custom paginator? Thanks

Ligonsker's avatar
Ligonsker's avatar Ligonsker2yrs agoCode Review
6
1
Last reply by Ligonsker 2yrs ago
yusufm's avatar

Livewire pagination middleware not working

When I navigate page, assigned middleware on route does not call. middleware class setGlobalRequestParams { public function handle(Request $request, Closure $next): Response { if(!isset($request->lan)) { $lang = app()->getLocale(); request()->merge(['lan' => $lang]); // $request->attributes->set('lan', $lang

yusufm's avatar
yusufm's avatar yusufm2yrs agoLivewire
5
1
Last reply by yusufm 2yrs ago
Chaeril's avatar

Livewire pagination find if it has more pages

I wanted an infinite scroll in livewire, and then used $this->perPage which was shown on some tutorials. now in the front end, I could use if ({{ $paginator->hasMorePages() }}) { @this.loadMore(); } to make sure it won't search for more data when we know there are no pages left. but how do i validate it in component. want to make sure that when loadMore is called

Chaeril's avatar
Chaeril's avatar Chaeril2yrs agoLivewire
0
1
TheDude's avatar

Typescript for Laravel pagination

//php return $paginator = myType::query()->paginate(5); //vue const props = defineProps<{ paginator:any, }>() let myType = ref<myType[] | null>(props.paginator.data) this works, but is there a type definition for the paginator?

TheDude's avatar
TheDude's avatar TheDude2yrs agoLaravel
0
1
GobssRuiz's avatar

Filter data and change pagination link

The filter works, but when I change the page, the link doesn't come with the query string, just the page number. How do I make the link in the query string keep the search/filter $data = Link::where('status', 'active'); $data = $data->join('link_pages', 'links.id', 'link_id'); // Parameters if (isset($_GET['title']) &

GobssRuiz's avatar
GobssRuiz's avatar tisuchi2yrs agoLaravel
1
1
Last reply by tisuchi 2yrs ago
Rretzko's avatar

Livewire Pagination Sorting on nested value

Hi All - I have an event. Each event has Participants and each Participant eager loads with a User object. I have columns for first,last, and middle names in the User table. I've set my Livewire component to paginate the Participants, and this is working as expected but ordering the Participants by their participant.id. I want the participants ordered by last/first and, so f

Rretzko's avatar
Rretzko's avatar Rretzko2yrs agoLivewire
9
2
Last reply by Rretzko 2yrs ago
johnDoe220's avatar

Different display of pagination on desktop and mobile

How in Laravel is exactly like laracasts. If we enter with desktop, the page is like this: Post::paginate() But on mobile or on smaller pages like this: Post::simplePaginate()

johnDoe220's avatar
johnDoe220's avatar tykus2yrs agoLaravel
9
1
Last reply by tykus 2yrs ago
deekepMaks's avatar

Sort by created_at with cursor pagination

I am using mongodb as a database (jenssegers/mongodb). I created a method to get users sorted by their account creation. There are more than 10 users, the first 10 are retrieved with the correct sorting, but when I get the next page, I get empty data, as if there are no more users. public function getUsers() { return User::orderBy('created_at', 'desc')->cursorPaginat

deekepMaks's avatar
deekepMaks's avatar deekepMaks3yrs agoLaravel
2
1
Last reply by deekepMaks 3yrs ago
seedphrase's avatar

Pagination previous &laquo; &raquo; next

Hey how can I hide « and &raquo without using v-htm? Thanks. <template v-for="(link, key) in links"> <div v-if="link.url === null" :key="key" class="mb-1 mr-1 px-4 py-3 text-gray-400 text-sm font-medium leading-4 bor

seedphrase's avatar
seedphrase's avatar JESSE CARD...2yrs agoInertia
8
1
Last reply by JESSE CARDOSO 2yrs ago
gizmojo's avatar

Overwrite pagination url path

How do you correctly use currentPathResolver? https://test.local/blog?=2 Paginator::currentPathResolver(fn ($pageName = 'page') => $this->url . '?' . $pageName); https://test.local/blog?page=&=2 Paginator::currentPathResolver(fn ($pageName = 'page') => $this->url); Reason for this is because I need to overwrite the url path inside a livewire component. Note t

gizmojo's avatar
gizmojo's avatar gizmojo3yrs agoLaravel
0
1
henock_barakael's avatar

How to store the results of a date range in cache so that when I leave a page to another (pagination) Laravel yajra datatable sever side no longer launches the query in the database to display the results

Hello, I want that when I select a date range that laravel yajra datatable store the data in cache so that when I do the paging that yajra no longer run the query in the database. COntroller: public function paydrc_daterange(Request $request){ $transactions = []; if(request()->ajax()) { $transactions = []; if(!empty($request->start

henock_barakael's avatar
henock_barakael's avatar LaryAI3yrs agoLaravel
1
1
Last reply by LaryAI 3yrs ago
MahmoudAdelAli's avatar

How to count collection pagination without duplicated queires

Hi , i have a data and i paginate it like that 'labels' => Label::latest()->paginate(25), and i count it using $labels->count() // Or total() but the queries is duplicated to get count select count(*) as aggregate from `labels` select * from `labels` order by `created_at` desc limit 25 offset 0 select count(*) as aggregate from `flags` select * from `flags` order

MahmoudAdelAli's avatar
MahmoudAdelAli's avatar webrobert3yrs agoLaravel
3
1
Last reply by webrobert 3yrs ago
alekv's avatar

Creating comments pagination

Hi everyone! I have a issue with creating eloquent relationship and comment paggination. This is a code: Recipe.php model: public function comments() { return $this->hasMany(Comment::class); } } Comment.php model: public function show() { return $this->belongsTo(Recipe::class, 'id'); } Currently on the view I show comments this way, and it is working: @forea

alekv's avatar
alekv's avatar alekv3yrs agoEloquent
5
1
Last reply by alekv 3yrs ago
movepixels's avatar

Help with sorting query for pagination

I have a multi relation query that needs to be sorted by a deep relation and can not seem to get it going. Model relations: Listing belongsTo Subscription Subscription hasMany Listing Subscription belongsTo Plan So I query all the Listing(s) that have an active Subscription and the Subscription includes the Plan but i cant get the Listing(s) that are subscribed to higher / lowe

movepixels's avatar
movepixels's avatar LaryAI3yrs agoLaravel
1
1
Last reply by LaryAI 3yrs ago
dr24's avatar

How to get all results (from all pages) in pagination in Laravel?

I have query that returns users with some data from search. Currently I get only users from first page, but I need to get all users from all pages. I am having trouble solving this with current setup.

dr24's avatar
dr24's avatar sirhxalot3yrs agoLaravel
6
1
Last reply by sirhxalot 3yrs ago
emilpapelas4@gmail.com's avatar

I have issues updating table data when i update the pagination.

<template> <div class="bg-white px-1 py-2 rounded"> <div class="container mx-auto py-2 px-4"> <h1 class="text-2xl py-2 border-b mb-3">All Offers</h1> <div class="mb-4 flex justify-between items-center"> <div class="flex-1 pr-4"> <div class="relative md:w-1/3&quo

emilpapelas4@gmail.com's avatar
emilpapelas4@gmail.com's avatar emilpapela...3yrs agoVue
0
1
moh120's avatar

how can i add pagination in this blade

@extends('layouts.master') @section('title') patient profile @endsection @section('css') <link rel="stylesheet" href="sweetalert2.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.6.9/sweetalert2.min.css"> <link rel="stylesheet" type="text/css" href=&

moh120's avatar
moh120's avatar moh1203yrs agoLaravel
7
1
Last reply by moh120 3yrs ago
bwrigley's avatar

Best practise for gathering a collection of child models for pagination

Still very new to Laravel and working on my first-ever project and I have some best practice questions about the architecture of a flashcards app that I'm building. I have two models topic and flashcard both with corresponding controllers. topic has a one-to-many relationship to child topics : $topic->children (which allows for a multi-level hierarchy). topic also has a one-

bwrigley's avatar
bwrigley's avatar webrobert3yrs agoDesign
8
1
Last reply by webrobert 3yrs ago
Randy_Johnson's avatar

Vue3 Pagination

Why is it that I can not use the bottom syntax. return Inertia::render('Users', [ 'users' => \App\Models\User::paginate(10)->through(fn($user) => [ 'id' => $user->id, 'name' => $user->name, ]), ]); return Inertia::render('Users', [ 'users' => \App\Models\User::select('id', 'name')->paginate(

Randy_Johnson's avatar
Randy_Johnson's avatar developer...3yrs agoVue
3
1
Last reply by developer alamin 3yrs ago
SERT12's avatar

how to set pagination with offset and limit. then how to show on blade. my code like that;

public function shipment(Request $request,$offset=0,$limit=0) { $rdf = $request->input('date-from'); $rdt = $request->input('date-to'); if($rdf == "" && $rdt == "") { return redirect()->route('gh'); } $date_from = ( $rdf == "" ) ? getLastSevenThDay() : date_format

SERT12's avatar
SERT12's avatar jlrdw3yrs agoLaravel
6
1
Last reply by jlrdw 3yrs ago
wikorl's avatar

Filter + Pagination table not working

I have a livewire component with a filament datepicker and a dropdown list on the top. With these two fields I am able to filter the table below. But whenever I want to go to the next page on the paginator I get an error message The GET method is not supported for this route. Supported methods: POST. Livewire Component class Overview extends Component implements HasForms {

wikorl's avatar
wikorl's avatar wikorl3yrs agoLivewire
2
1
Last reply by wikorl 3yrs ago

Want us to email you occasionally with Laracasts news?

Nine out of ten doctors recommend Laracasts over competing brands. Come inside, see for yourself, and massively level up your development skills in the process.

Learn
BrowseSeriesCreatorSeriesLaravel PathLarabitsPlayground
Discuss
ForumPodcastSupport
Extras
Gift CertificatesApparelFAQiOS AppTerms
Social
X(Twitter)TikTokYoutube

© Laracasts 2026. All rights reserved. Yes, all of them. That means you, Todd.

Proudly hosted with Laravel Forge and DigitalOcean.

Want us to email you occasionally with Laracasts news?

Nine out of ten doctors recommend Laracasts over competing brands. Come inside, see for yourself, and massively level up your development skills in the process.

Learn
BrowseSeriesCreatorSeriesLaravel PathLarabitsPlayground
Discuss
ForumPodcastSupport
Extras
Gift CertificatesApparelFAQiOS AppTerms
Social
X(Twitter)TikTokYoutube

© Laracasts 2026. All rights reserved. Yes, all of them. That means you, Todd.

Proudly hosted with Laravel Forge and DigitalOcean.