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

movepixels's avatar

Laravel Pagination

Is there a way to not show the numbers 1 thru 10 and pass an option to only show 1-5? 1 thru 10 breaks on smaller screens so it would be nice to display < << 1 - 5 >> >

movepixels's avatar
movepixels's avatar Lumethys3yrs agoLaravel
4
1
Last reply by Lumethys 3yrs ago
TimiAde's avatar

Pagination links not working in livewire

public function paginate($items,$perPage) { $pageStart = \Request::get('page', 1); // Start displaying items from this number; $offSet = ($pageStart * $perPage) - $perPage; // Get only the items you need using array_slice $itemsForCurrentPage = array_slice($items, $offSet, $perPage, true); return new LengthAwarePaginator($

TimiAde's avatar
TimiAde's avatar jlrdw3yrs agoLivewire
26
1
Last reply by jlrdw 3yrs ago
lat4732's avatar

How to set max possible pages display of the pagination

Hello everyone! Quick look at this photo is showing the problem Here is how I'm currently paginating the results $logs = CompanyActionsLog::where('company_id', $companyData->id)->orderBy('spent_at', 'DESC')->where('type', 'decrement')->where('is_system_log', 0)->paginate(3, ['*'], 'logsPage')->onEachSide(1); How can I fix this problem? onEachSide() doesn't h

lat4732's avatar
lat4732's avatar Tray23yrs agoLaravel
3
1
Last reply by Tray2 3yrs ago
jurietylier's avatar

How to Insert data without getting at page 1 in pagination im using laravel and jquery

when i use .table on load href in jquery it will getting back to page number 1 anyone have an idea about this?

jurietylier's avatar
jurietylier's avatar MohamedTam...3yrs agoGeneral
5
1
Last reply by MohamedTammam 3yrs ago
Nevda's avatar

Laravel Pagination returns wrong order!

Hi everyone. I'm working on this new project, and I'm so confused with this problem. So, I want to get data using paginate() and before that I want to order data by created_at > ASC. I see, it returns data with opposite order! No matter if I use DESC or ASC, in both case, result is opposite. No matter if I order data by created_at or by ID. It always returns from down to top

Nevda's avatar
Nevda's avatar Nevda3yrs agoLaravel
6
1
Last reply by Nevda 3yrs ago
mralston's avatar

setAppends() with eager loading & pagination

I have an attribute which is somewhat intensive to run. I want to append the attribute to the model only when needed, so I'd like to use the setAppends() method when I need it, rather than the $appends property which would append the attribute every time. The context I'm doing it in is confusing me. The model with the attribute is being eager loaded on a relationship using the

mralston's avatar
mralston's avatar rodrigo.pe...3yrs agoEloquent
5
1
Last reply by rodrigo.pedra 3yrs ago
stefanp's avatar

filtered result after pagination

Hi, I have the followinng query builder $unitBuilder = Unit::isActive()->with('city')->where('has_images', 1)->where('closed', 'no')->where('person_nr', '>=', $guests])->orderBy('rating'); if I try to filter the results with: $result = $unitBuilder->where('name', 'My Unit Name')->whereIn('city_id', [1, 5, 6])->get(); i have the following dd() output

stefanp's avatar
stefanp's avatar stefanp3yrs agoEloquent
2
1
Last reply by stefanp 3yrs ago
vincent15000's avatar

How to go to a specifig page with pagination ?

Hello, I'm testing InertiaJS with VueJS 3 and the Element-Plus CSS framework. I can change the page size (number of items displayed) but I can't change the page which is displayed. I can send a query with the page number to display, but this can work only if I can directly load a specitif page number. Is it possible to do that in the controller ? Thank you for your help. V

vincent15000's avatar
vincent15000's avatar vincent150...3yrs agoLaravel
3
1
Last reply by vincent15000 3yrs ago
sultanwebdev's avatar

join table cant Display pagination & View Page Data

Function here any one help me please public function SubCategory(){ $subcategory = DB::table('subcategories') ->join('categories','subcategories.category_id','categories.id') ->select('subcategories.*','categories.category_en') ->orderBy('id','desc') ->paginate(5); return view('backend.subcategory.subcategory',compact('subcategory')); }// e

sultanwebdev's avatar
sultanwebdev's avatar jlrdw3yrs agoLaravel
5
1
Last reply by jlrdw 3yrs ago
i74ifa's avatar

http returned in pagination links laravel 9

I have a link in cloudflare that contains https but when I use paginate in laravel it returns absolute url http my url: https://example.com/page paginate url: http://example.com/page?page=1 route helper url: // its currect https://example.com Information that may help: ssl cloudflare laravel 9 with vuejs and inertia nginx server error in devtool: vue.m.d2280705.js:32 Mixed

i74ifa's avatar
i74ifa's avatar Sinnbeck3yrs agoLaravel
1
1
Last reply by Sinnbeck 3yrs ago
KLM113's avatar

Datatables vs server side pagination

Kinda offtopic, I hope it's still allowed. I see a lot of applications using datatables, I would like to use it too because you get a lot of nice controls out of the box and also without having to request the server with every interaction. However, in order to get this working you need to retrieve the full set of records at once, right? Isn't this horrible performance wise? Am

KLM113's avatar
KLM113's avatar martinbean3yrs agoDesign
5
1
Last reply by martinbean 3yrs ago
stigo-rigo's avatar

LARAVEL API PAGINATION & FILTER WITH THE SAME END POINT

I'm using laravel for my api and vue 3 for frontend. I want to display the paginated results on a table, and filter the table column by type, phone , date and status. I am currently getting the paginated Data results on my table, but I want to get both paginatedData and search results with one api endpoint... This is my controller: public function paginatedData(Request $reque

stigo-rigo's avatar
stigo-rigo's avatar stigo-rigo3yrs agoLaravel
5
1
Last reply by stigo-rigo 3yrs ago
unknown_'s avatar

Pagination - $i+1 not working

I added the paginate method to my code (5 posts per page), but when I go onto the next page it shows the numbers from 1 to 5, even though they should be from 6 to 10. This is my index.blade.php: <table class="table table-bordered"> <tr> <th>No</th> <th>Title</th> <th>Description</th> &

unknown_'s avatar
unknown_'s avatar Sinnbeck3yrs agoLaravel
9
1
Last reply by Sinnbeck 3yrs ago
ngoquocdat's avatar

Pagination limit page item

Hi guys How can I limit the page item. E.g. currently it shown from 1 to 10 ... max I want to it show 1 to 5 ... max like this Thanks guys!!

ngoquocdat's avatar
ngoquocdat's avatar Snapey3yrs agoLaravel
3
1
Last reply by Snapey 3yrs ago
Aishan's avatar

Pagination using ajax to prevent page reload in laravel 8

I am using an ajax code which I have copied from internet to paginate through my table result in my laravel project, it works fine on normal table, but when I am applying the same code for search result inside table it works until I search something and it shows me the number of pages , but as soon as I click on the pages to see the result it takes me back to normal paginated p

Aishan's avatar
Aishan's avatar jlrdw3yrs agoLaravel
3
1
Last reply by jlrdw 3yrs ago
joshmanhuwa's avatar

Re-writting a query for pagination

Hi kindly help re-write this script so that i can compact a paginated result. public function property(Request $request) { $query = Property::query(); if ($request->status) $query->where('status', '=', $request->status); if ($request->type) $query->where('type', '=', $request->type); if ($request->bedrooms) $query->where('bedrooms', '=',

joshmanhuwa's avatar
joshmanhuwa's avatar jlrdw4yrs agoLaravel
1
1
Last reply by jlrdw 4yrs ago
qwewq's avatar

Why does the ajax pagination not work without page reload?

Hello! I'm using laravel 9 with bootstrap. I've been told that in laravel 9 we need to change the code of AppService Provider to make it work with bootsrap. I did that: <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Pagination\Paginator; class AppServiceProvider extends ServiceProvider { /** * Register any application servic

qwewq's avatar
qwewq's avatar qwewq4yrs agoLaravel
4
1
Last reply by qwewq 4yrs ago
EckyEckyPtang's avatar

Add horizontal scrollbar and pagination at the top?

Is there a non-hacky way to put a scrollbar and navigation elements at the top of the index table? If you have 100 records it's a hassle to scroll down each time.

EckyEckyPtang's avatar
EckyEckyPtang's avatar EckyEckyPt...4yrs agoNova
0
1
OurBG's avatar

Inertia mounted hook with search resets pagination on every action

I'm following Jeffrey Way's tutorial on Inertia for a project I'm building This one My vue file: data() { return { search: '', } }, mounted() { this.search = this.filters.search ?? ''; }, watch: { search(value) { Inertia.get('/contacts', { search: value }, { preserveState: true, replace: true, }) } My controller: $contacts =

OurBG's avatar
OurBG's avatar undeported...4yrs agoInertia
3
1
Last reply by undeportedmexican 4yrs ago
mahbubrn's avatar

How to get data toArray with pagination

Here is my code. $orders = Order::with('customer')->withCount('orderItems')->paginate(50)->toArray(); This code return me the blank page. No data return. So here's what I did wrong?

mahbubrn's avatar
mahbubrn's avatar jlrdw4yrs agoEloquent
3
1
Last reply by jlrdw 4yrs ago
monstajamss's avatar

Displaying Pagination Link

I am trying to work on navigation on my laravel and nuxtjs navigation so i did this in my controller public function index() { $posts = Post::orderBy('created_at', 'desc')->paginate(10)->through(fn($post) =>[ 'id' => $post->id, 'title' => $post->title, 'body' => $post->body, 'excerpt' => $

monstajamss's avatar
monstajamss's avatar proxomos2yrs agoVue
10
1
Last reply by proxomos 2yrs ago
fcno's avatar

belongsToMany relationship orderBy relationship existence, followed by abstinence using pagination

Hello! Laravel version 9.x PHP version 8.1 Current code: /** * Show the form for editing the specified resource. * * @param \App\Models\Site $site * * @return \Illuminate\Http\Response */ public function edit(Request $request, Site $site) { $result = Server::select('id', 'name') ->orderBy('name', 'asc') ->simpl

fcno's avatar
fcno's avatar fcno4yrs agoLaravel
3
1
Last reply by fcno 4yrs ago
mstdmstd's avatar

With custom template pagination onEachSide parameter does not work

Hello, I laravel 8 I set onEachSide = 3: $nominated_photos_per_page= 14; $nominatedPhotos = PhotoNomination ... ->paginate($nominated_photos_per_page, array('*'), 'page', $page) ->onEachSide(3) but it does not work and I got links from 1 till 20. I use custom template : @if ($paginator->hasPages()) <div class=&qu

mstdmstd's avatar
mstdmstd's avatar mstdmstd4yrs agoLaravel
3
1
Last reply by mstdmstd 4yrs ago
kuns25's avatar

How to use Laravel pagination in loop

Hello everyone, I am trying to store my API resource response in .json file. I'm having two issue i don't how i can get data of next page in the loop and the second issue is i cant store data of $response in .json file until i write $response->toJson() . but this for some reason removes meta data $posts = Post::paginate(10); for ($i=1; $i <= $posts->

kuns25's avatar
kuns25's avatar kuns254yrs agoLaravel
11
1
Last reply by kuns25 4yrs ago
tako's avatar

Order by with pagination

Is there a way to sort all the columns from all pages ? I use this but it only sort in the current page and I would like to sort it from the first page to the last one. Product::orderByDesc('updated_at')->paginate(30);

tako's avatar
tako's avatar Sinnbeck4yrs agoLaravel
3
1
Last reply by Sinnbeck 4yrs ago
fcno's avatar

CTE pagination Laravel/Mysql 8

Hello guys. Some time ago I saw here on this forum a link to an explanation on how to paginate results in CTE queries. With reasonable certainty, I think that the user @jlrdw was the author of the explanation (I remember that it was very detailed on the subject). However, I've looked all over here and can't find it. If someone has already gone through this need and can indicate

fcno's avatar
fcno's avatar fcno4yrs agoEloquent
4
1
Last reply by fcno 4yrs ago
ImWaller's avatar

Delete the one and last data from page of pagination and return to page with content

Hey, I use jetstream with inertiajs and vue 3. I delete the one paginator data in last page and redirect to the same page without content. I try to figure out how to redirect to first page with content/data without return to previous page without data. For example I have 2 pages and every paginator page have 9 items in total, but the second one have only one item. I delete the

ImWaller's avatar
ImWaller's avatar jlrdw4yrs agoLaravel
9
2
Last reply by jlrdw 4yrs ago
NeVeDlE's avatar

Pagination to 2 seperate variables

Hello, I'm trying to make a search in my website which works on posts/users, so i want if a user searched for something the code will search for it 2 models like here //That's inside the Post Model public function scopeFilter($query, $search) { $query->when($search ?? false, function ($query, $search) { $query->where(function ($query) use ($sear

NeVeDlE's avatar
NeVeDlE's avatar Sinnbeck4yrs agoEloquent
19
3
Last reply by Sinnbeck 4yrs ago
FounderStartup's avatar

Pagination in filter page not working properly

I need to filter the brokers list page with dropdown city My controller : public function Brokersincity(Request $request){ $city = $request->project_city; $brokerscount = User::where('role', 2 )->where('city', $city )->where('status', 1)->count(); $brokers = User::where('role', 2 )->where('city', $city )->where('status', 1)->pagina

FounderStartup's avatar
FounderStartup's avatar FounderSta...4yrs agoLaravel
9
1
Last reply by FounderStartup 4yrs ago
snipesnipes's avatar

Laravel 8 pagination need help !

Hello , since I upgraded to Laravel 8 I have that bug : I got a search box and I paginate the results and if the limit is above the search result count than it shows nothing but when the limit is below the result I got the result displayed ... same code works on a Laravel 7 . When I put get() insdeaf of ->paginate(150); then it is ok I see everything. {!! $items->render(

snipesnipes's avatar
snipesnipes's avatar jlrdw4yrs agoLaravel
5
1
Last reply by jlrdw 4yrs ago
electric18's avatar

Relationships Pagination

I have a model being returned from a controller. I eager load some relationships using 'with' like so. $item = Item::with('reviews.user') ->withCount('reviews') ->where('volume_id',request()->get('volume_id')) ->first(); I would like to paginate the items reviews but have not been able to find a way. Is there a way to specifically paginate a relationship?

electric18's avatar
electric18's avatar electric184yrs agoEloquent
7
1
Last reply by electric18 4yrs ago
panthro's avatar

Passing a parameter to control the number of items returned by pagination?

I'm looking for a way to pass a value to my paginate method, so I can control the number of results for my GET request: ->cursorPaginate($items) I know I can get the value from the query string, and even set a default if not present. But I am wondering how do you go about setting a min and max setting, e.g. so a user cannot access 10,000 records at once? I'm aware of this p

panthro's avatar
panthro's avatar panthro4yrs agoLaravel
4
1
Last reply by panthro 4yrs ago
hillcow's avatar

Laravel performance: How to use pagination with index?

When using Laravel's paginate(20) method, the MySQL query looks like this at the end: limit 20 offset 0; To my understanding, therefore Laravel has to scan the entire table instead of using an index. The right way to go would be to apply the limit in the where clause somehow. How do you handle this? Is there a package or something that takes care of that? I don't really want to

hillcow's avatar
hillcow's avatar hillcow4yrs agoLaravel
2
1
Last reply by hillcow 4yrs ago
ynoth25's avatar

Laravel Pagination and resource controller

I have a resource controller (index) that returns a paginated data, Is there a way where I can pass a parameter to the resource (index) as a filter for my query in the resource controller? current_url: http://127.0.0.1:8000/students?page=3

ynoth25's avatar
ynoth25's avatar Snapey4yrs agoLaravel
14
1
Last reply by Snapey 4yrs ago
prospero's avatar

Livewire pagination!

Someone can tell me, if passing a value to paginate like, eg. 500 (->paginate(500)) can receive an HTTP ERROR 500??? I have dropdown for bulk with 100, 500 and All options values. For the 100 and All everything works well, but on 500 the browser pop up a black screen and in console I get: Failed to load resource: the server responded with a status of 500 () If I change the

prospero's avatar
prospero's avatar prospero4yrs agoLivewire
2
1
Last reply by prospero 4yrs ago
boyjarv's avatar

Implementation of pagination on NUXT project

Can anyone help me please, I’m trying to get the plug-in Laravel-Vue-pagination working on my NUXT project, I’ll buy you a coffee!

boyjarv's avatar
boyjarv's avatar kuns254yrs agoVue
20
1
Last reply by kuns25 4yrs ago
nekooee's avatar

how to redirect back to the last page (when using pagination)?

Hi After the user submits a new post, he should return to the last page. Because a new page may have been added, or the user may not have posted from the last page. Now I use the following code which goes back to the previous page, not the last page. return back()->with(['flashMessage' => $message, 'flashSubject' => $subject]);

nekooee's avatar
nekooee's avatar nekooee4yrs agoLaravel
12
3
Last reply by nekooee 4yrs ago
rjrocks's avatar

Can't display the pagination links in blade file

This is livewire file:

rjrocks's avatar
rjrocks's avatar webrobert4yrs agoLivewire
14
1
Last reply by webrobert 4yrs ago
bajki's avatar

Laravel 8 Pagination page=1

Hi, i would like to remove page=1 from query. Is there any way to overide url() function in AbstractPaginator /** * Get the URL for a given page number. * * @param int $page * @return string */ public function url($page) { if ($page <= 0) { $page = 1; } // If we have any extra query string key / value pairs that need to be added // onto the UR

bajki's avatar
bajki's avatar webrobert4yrs agoLaravel
1
1
Last reply by webrobert 4yrs ago
christogonus's avatar

Livewire Pagination Returns Error When I return to page 1

I have made a Livewire component to show a list of codes, paginate in sets of 20. The first time I load the page, everything works fine, I can go from page1 - page 5 But when I go from other pages back to Page 1, it throws error as seen here ErrorException Undefined offset: 7 (View: C:\xampp\htdocs\clients\dashboard\resources\views\livewire\promo-code\dashboard.blade.php) http:

christogonus's avatar
christogonus's avatar christogon...4yrs agoLivewire
3
1
Last reply by christogonus 4yrs ago
aleahy's avatar

Pagination of discussion searches seems broken

Hi @JeffreyWay, If I do a search in the discussions, and the results are paginated, clicking on the next page seems to lose the search query. i.e. Instead of https://laracasts.com/discuss?q=query&page=2 we get https://laracasts.com/discuss?page=2

aleahy's avatar
aleahy's avatar siangboon4yrs agoFeedback
1
1
Last reply by siangboon 4yrs ago
samdesgn's avatar

pagination mount laravel

hello, so i have a problem with livewire laravel. I pass a value to my Livewire component using a controller. @livewire ('posts', ['posts' => $ posts], key ($ posts-> id)) I just want to do a paging because the post variable can either send all the posts of the table or that of a user. how to do it please?

samdesgn's avatar
samdesgn's avatar samdesgn4yrs agoLivewire
1
1
seqond's avatar

Pagination with having clause

Laravel 6 please help. pays its a hasManyThrough relation. $orders->withCount(['pays as pay_sum' => function (Builder $q) { return $q->select(DB::raw('SUM(invoice_pays.sum)')); }])->havingRaw('pay_sum >= `orders`.`amount`') //->get(); Everything works well ->paginate(10);

seqond's avatar
seqond's avatar jlrdw4yrs agoEloquent
1
1
Last reply by jlrdw 4yrs ago
Zoul's avatar

Custom pagination not working with ajax

Hi all, I'm trying to apply ajax, so that the page is not refreshed when i press next,prev buttons, but the page is still reloading, i tried to manipulate the data in different ways but none worked for me, has anyone an idea of what's going wrong please ? Thanks =in my TeamController public function index(){ $members = Member::latest('id')->paginate(6); r

Zoul's avatar
Zoul's avatar Zoul4yrs agoLaravel
2
1
Last reply by Zoul 4yrs ago
georgefromohio's avatar

Cursor Pagination on Eloquent Models

Has anyone got enough time with Laravel 8.4.*? Particularly the cursorPaginate method? I'm pulling my hair out and any help would be appreciated. I've got two scenarios: People::cursorPaginate($request->query('limit')) This works great with the links to the next page and previous pages. However!! When I add an orderBy or orderByDesc as mentioned in the docs, none of the lin

georgefromohio's avatar
georgefromohio's avatar georgefrom...4yrs agoLaravel
9
1
Last reply by georgefromohio 4yrs ago
Ifrit's avatar

Pagination not showing post

I've got a query that I'm paginating and the issue I'm having is that if my data is less then what my paginate has then it doesn't show. So for example if I have 9 posts and my ->paginate(10) then it doesn't show, but if I change to ->paginate(5) then it shows Here is my code $posts = DB::connection('blog') ->table('posts')

Ifrit's avatar
Ifrit's avatar Ifrit5yrs agoLaravel
2
1
Last reply by Ifrit 5yrs ago
skoobi's avatar

pagination with collection

Hi. I've got an issue when trying to paginate a collection, but as its a collection there is no paginate. I need to sort the data in a way that it orders it correctly and grabs the first in the group rather than show all the scans, is there a way I can put it into one so I can paginate ? $collection = CustomerScan::where('user_id', Auth::user()->id) ->orde

skoobi's avatar
skoobi's avatar skoobi4yrs agoLaravel
5
1
Last reply by skoobi 4yrs ago
Deekshith's avatar

Merge different get query results with pagination in array format

i am using corcel package to get wordpress posts and i am getting all the posts which matches some categories like below, $categories = ['current-affairs-2','current-events-2','editorials']; $related = new Collection([]); // return $pagedetail->assignedcategories->first(); foreach($categories as $cat) {

Deekshith's avatar
Deekshith's avatar Deekshith5yrs agoLaravel
4
1
Last reply by Deekshith 5yrs ago
jmacdiarmid's avatar

Unable to get Livewire v2 pagination working.

I have a companies component and been trying to get this to work for what seems like at least a week. [rant]The Laravel docs are good for some things however it's missing a lot including more FULL examples, not vague partial examples. I've run into this many times and I'm left to seek out other sources for information. [/rant] Anyway, it looks like I need to use a ResourceCol

jmacdiarmid's avatar
jmacdiarmid's avatar jmacdiarmi...5yrs agoLivewire
9
1
Last reply by jmacdiarmid 5yrs ago
mvpop's avatar

Livewire Pagination Error - The GET method is not supported for this route.

So I have the following route: Route::get('produse/', 'ProduseController@index')->name('arataProduse'); And I return a blade view return view('produse.index'); from ProduseController@index Now in my blade view I load a Livewire component <livewire:component-name /> The component is basically a datatable with some crud functionality taken care by Livewire. THE PROBLEM O

mvpop's avatar
mvpop's avatar ahmedkandi...1yr agoLivewire
21
1
Last reply by ahmedkandil 1yr 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.