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

motazdev's avatar

Pagination with findorfail

hey guys, i'm trying to paginate a products of specific category route. $category = Category::with('products')->findOrFail($id)->paginate(12); but it gives me that error Undefined property: Illuminate\Pagination\LengthAwarePaginator::$category how to solve this please?

motazdev's avatar
motazdev's avatar jlrdw5yrs agoLaravel
8
1
Last reply by jlrdw 5yrs ago
ImWaller's avatar

Inertia pagination, how to use...

Hello everyone, how to use this lib: https://github.com/svnwa/InertiaVuePaginator I follow the instructions but it never works.

ImWaller's avatar
ImWaller's avatar ImWaller5yrs agoInertia
2
1
Last reply by ImWaller 5yrs ago
alex_hill's avatar

Sort Collection by accessor with pagination

I have two many to many related models: Contact Catchup The Contact model has two accessors to determine the last catchup, and next catchup (based on a calculation): public function catchups() { return $this->belongsToMany(Catchup::class); } public function getLastCatchupAttribute() { return \Carbon\Carbon::create($this->catchups()->

alex_hill's avatar
alex_hill's avatar alex_hill5yrs agoEloquent
1
1
Last reply by alex_hill 5yrs ago
UsmanBasharmal's avatar

Laravel 8 pagination return the same data (offset is ignored - it is always zero)

I have code like this in controller: $MyItems = App\Models\MyItems::paginate(10); On URL https://example.com/my-item it will execute SQL: array:2 [▼ 0 => array:3 [▶] 1 => array:3 [▼ "query" => "select * from `teams` order by `name` asc limit 10 offset 0" "bindings" => [] "time" => 0.33 ] ] On URL https:/

UsmanBasharmal's avatar
UsmanBasharmal's avatar MichalOrav...5yrs agoLaravel
4
1
Last reply by MichalOravec 5yrs ago
asoftware's avatar

Random Order a Collection With Pagination

I have a collection of 50 items (model = Books) and I would like to return them uniquely 10 per page (paginated) but in a random order. I tried using Book::inRandomOrder()->paginate(10), but when I go to page 2, 3, etc... I see books that were already shown on page 1 or some previous page. I did a workaround with adding a randomValue column to the table and then doing orderB

asoftware's avatar
asoftware's avatar seanworks5yrs agoEloquent
11
4
Last reply by seanworks 5yrs ago
Froedrick's avatar

Software design question reg pagination and external api

The Movie DB database has a route to get the movies in a list. It returns 20 items at a time and the user has the option to include a query string designating the page number https://www.themoviedb.org/list/8434?page=2 My routes look like this Route::get('/list/{id}', 'MoviesController@list')->name('movies.list'); Route::get('/list/{id}/{page}', 'MoviesController@list')->

Froedrick's avatar
Froedrick's avatar krisi_gjik...2yrs agoGeneral
3
1
Last reply by krisi_gjika 2yrs ago
Spiral's avatar

custom pagination with limit & offset

Hi! I have 100 records in the database. I want to show per page 10 if the user click on the show more then I will give him 10 more records with the existing 10 records with limit & offset plz give me a solution so or link wherefrom I could solve my problem

Spiral's avatar
Spiral's avatar tykus5yrs agoLaravel
14
1
Last reply by tykus 5yrs ago
sshateri's avatar

Pagination error

im trying to retrive the users on page mount and paginate them using the following code: public function mount() { $this->users = User::paginate(16); } but im getting this error: Livewire component's [user-search] public property [users] must be of type: [numeric, string, array, null, or boolean]. Only protected or private properties can be set as other typ

sshateri's avatar
sshateri's avatar sshateri5yrs agoLivewire
4
1
Last reply by sshateri 5yrs ago
edgreenberg's avatar

Illuminate Pagination

Somewhere between 5.8 and 6.0, PaginatedResourceResponse::toResponse() changed. In 5.5, in an API controller, I did a query and passed it to ->paginate($num) instead of to get() and then pushed the result set into a new ApplicationCollectionResource();. The result of that (a resource) was then returned. This would work. In 6.0, when the resource is returned. it winds up in

edgreenberg's avatar
edgreenberg's avatar edgreenber...5yrs agoCode Review
7
1
Last reply by edgreenberg 5yrs ago
jorgb's avatar

livewire query pagination scope

Is there a best practise for applying global query scopes from within a Livewirecomponent? Since there is no request going through the middleware enforcing the scope this gets ignored when accessing the paginated pages Normally all livewire requests are passed through the web middleware but on specific routes i would like the livewire render requests to go through additional mi

jorgb's avatar
jorgb's avatar jorgb5yrs agoLivewire
1
1
Last reply by jorgb 5yrs ago
webfuelcode's avatar

How to add pagination in user's posts

@forelse ($user->posts as $post) <div class="col-md-6 col-lg-4"> <div class="card mb-4"> @if (!empty($post->img1)) <img src="/uploads/post_img/{{ $post->img1 }}" class="card-img-top">

webfuelcode's avatar
webfuelcode's avatar Tray25yrs agoLaravel
5
1
Last reply by Tray2 5yrs ago
jaeyson's avatar

Pagination: Random data without repeating

hi! how do i return a random data without repeating it? $photos = Photos::inRandomOrder() ->where(['popular' => 'y']) ->paginate(30) ->onEachSide(1); return $photos; i had the same inquiry like this.

jaeyson's avatar
jaeyson's avatar jaeyson5yrs agoLaravel
11
1
Last reply by jaeyson 5yrs ago
Maria30's avatar

How to return the pagination results?

Those results are from an Api current_page 1 data 0 Rank 1 Status "Recruiting" NCTId "NCT04682574" Organization "University of Lahore" Sponsor "University of Lahore" 1 Rank 2 Status "Not yet recruiting" NCTId "NCT04682561" Organization "St. Michael's Hospital, Toronto" Sponsor "St. Michael's Hospita

Maria30's avatar
Maria30's avatar jlrdw5yrs agoLaravel
1
1
Last reply by jlrdw 5yrs ago
Ajvanho's avatar

Pagination change refreshes the page?

That shouldn't be in Livewire and so far I have had no problems, but now refreshes?!? <?php namespace App\Http\Livewire; use Livewire\Component; use Livewire\WithPagination; use App\Models\Post; use App\Models\Comment; class BrowseComments extends Component { use WithPagination; public $post; public function mount(Post $post) { $this->post = $post;

Ajvanho's avatar
Ajvanho's avatar Snapey5yrs agoLivewire
9
1
Last reply by Snapey 5yrs ago
mehrdad70's avatar

pagination dynamic in laravel

How can I make this public function index() { $articles = Article::paginate(); return view('admin.articles.index' , compact('articles')); } <div aria-label="Page navigation example"> <ul class="pagination mb-0"> <li class="page-item"><a class="page-link

mehrdad70's avatar
mehrdad70's avatar MichalOrav...5yrs agoLaravel
4
1
Last reply by MichalOravec 5yrs ago
RoyGoode's avatar

how to disable livewire tailwind pagination in laravel blades?

.. how to use bootstrap in blades not in components!

RoyGoode's avatar
RoyGoode's avatar RoyGoode5yrs agoLivewire
4
1
Last reply by RoyGoode 5yrs ago
Antonella's avatar

problem filter dropdown and pagination livewire

null

Antonella's avatar
Antonella's avatar Antonella5yrs agoLivewire
0
1
kkhicher1's avatar

Pagination + inRandomOrder duplicate Record Fetch

$page = \request()->input('page', 1); $images = Cache::remember('images-'.$page, 60*60, function (){ return Image::inRandomOrder()->paginate(10); }); return json_encode($images); next page duplicated record fetch and cache in not problem. i tried before implementing cache system

kkhicher1's avatar
kkhicher1's avatar MichalOrav...5yrs agoLaravel
7
1
Last reply by MichalOravec 5yrs ago
Deekshith's avatar

laravel pagination go to specific page which has particular post id

I have forum application where every thread will have posts so now i am storing last viewed page in database and if user again visits the same thread then i should redirect to that particular page. how can i do this? now i am using below code to redirect to last page by default, f($request->page == '') { $lastPage = $thread->posts()->where('first_post',

Deekshith's avatar
Deekshith's avatar a4ashraf5yrs agoGeneral
1
2
Last reply by a4ashraf 5yrs ago
matz's avatar

API Resource with pagination

Hi, I'm a little bit confused after upgrading to Laravel 8. With my upgraded application, no change. So yesterday I created a fresh application and used API Resource like always. class UserCollection extends ResourceCollection { /** * Transform the resource collection into an array. * * @param \Illuminate\Http\Request $request * @return array */

matz's avatar
matz's avatar matz5yrs agoLaravel
8
5
Last reply by matz 5yrs ago
orest's avatar

override pagination data

when i query the activities table and eager load a relationship, i want the paginated data to contain only the relationship data and not the activity data. array:12 [ "current_page" => 1 "data" => array:1 [ 0 => array:8 [ "id" => 1 "user_id" => "1" "type" => "created-thr

orest's avatar
orest's avatar jlrdw5yrs agoLaravel
1
1
Last reply by jlrdw 5yrs ago
Hekmatyar's avatar

Pagination translate is not working

Hi, i have a problem with "SimplePaginate" https://i.imgur.com/oizsM5M.png https://i.imgur.com/erOsx4C.png https://i.imgur.com/Ia5Nz2L.png https://i.imgur.com/ASRWuFJ.png

Hekmatyar's avatar
Hekmatyar's avatar Hekmatyar5yrs agoLaravel
0
1
BunsinNANH's avatar

Laravel 7 pagination display blank next pages after filter

When filtering the data it has been returned well with paginate but when clicking the next pages it returned blank pages. My controller function public function filter(Request $request) { $cat_id = $request->input('cat_id'); $categories = Category::where('cat_id','LIKE','%'.$cat_id .'%')->paginate(10); return view('myview', compact('categories')); }

BunsinNANH's avatar
BunsinNANH's avatar BunsinNANH5yrs agoLaravel
15
1
Last reply by BunsinNANH 5yrs ago
Andreas94's avatar

infinite scroll on pagination repeats elements

i have a sitoweb structured in: {$items} {$video} {$other_items} in $items are printed 12 items, while in $other_items 4 items, discarding the 12 printed before. $articoli = Articoli::where('is_published', '0')->orderBy('published_at', 'desc')->limit(12)->get(); $articoli_other = Articoli::where('is_published', '0')->where('id', '<', $articoli[11]->id)->ord

Andreas94's avatar
Andreas94's avatar Andreas945yrs agoGeneral
3
1
Last reply by Andreas94 5yrs ago
TomasAm's avatar

Raw query pagination

How do I paginate a raw call from database? public function index() { $data = DB::select(DB::raw('select * from categories', [1])); $products = DB::select(DB::raw('select * from products', [1]))->paginate(8); dd($products); return view('products.products', ['data' => $data], ['products' => $products]); } I tried this, but it

TomasAm's avatar
TomasAm's avatar mabdullahs...5yrs agoLaravel
2
1
Last reply by mabdullahsari 5yrs ago
orest's avatar

append attribute to pagination

I'm trying to append an attribute to paginated data during runtime. More specifically, i have a Reply model and i want to append the following attribute public function getIsLikedAttribute() { return $this->likes()->exists(); } In the controller i have the following line $replies = $thread->replies()->paginate(Reply::PER_PAGE); Then the $replies d

orest's avatar
orest's avatar themightys...11mos agoLaravel
12
2
Last reply by themightystephen 11mos ago
mohamedhamidi's avatar

Split a page into multiple pages using pagination

I am making a blog , in the blog.show.blade view sometimes the body is too long and want to divide it into parts and add 'previous' , 'next' buttons , but the problem is that the body is stored all in one column in database so how can i paginate it ? show.blade.php (the article show view) : @if($post->image_url) <div class="post-image"&g

mohamedhamidi's avatar
mohamedhamidi's avatar mohamedham...5yrs agoLaravel
14
1
Last reply by mohamedhamidi 5yrs ago
Entropi's avatar

Nested relationships with ordering and pagination

Hi all, I'm trying build an achievements system using the simplified database schema and models listed at the bottom of this post. I've hit a bit of a roadblock when figuring out how to retrieve a user's unlocked achievements while ordering them and paginating. The following is an example of my desired result to be outputted: Category 1 - Sequence 1 - Achievement 1 -

Entropi's avatar
Entropi's avatar Entropi5yrs agoEloquent
5
1
Last reply by Entropi 5yrs ago
phoennix's avatar

Implementation of multiple pagination on Laravel 7

Hello, I'm trying to integrate several paginations on Laravel and I encounter a problem. Here is my code: $selectedCompanies = $selectedCampaign->companies->paginate(1); $selectedCompanies->setPageName('other_page'); dd($selectedCompanies->currentPage()); If I go to URL/users/ID?other_page=2, I always get 1 on the currentPage. Is this normal

phoennix's avatar
phoennix's avatar jlrdw5yrs agoLaravel
4
1
Last reply by jlrdw 5yrs ago
phoennix's avatar

Pagination after a sortBy on Eloquent

Hello, I'm trying to paginate within an Eloquent but impossible request, I always get an error telling me that paginate() or simplePaginate() doesn't exist. $selectedInterviews = Company_Interview::all()->sortBy(function ($temp, $key) { return Carbon::parse($temp['interview_date'] . ' ' . $temp['start_time'])->getTimestamp(); }); Do you have an idea o

phoennix's avatar
phoennix's avatar MichalOrav...5yrs agoLaravel
2
1
Last reply by MichalOravec 5yrs ago
Muaath_Alhaddad's avatar

Parent component only pass the dynamic v-modal ID to the child of the first page in pagination

I am using [email protected] and [email protected] I am having a component called index.vue to list all customers. and a child component customerModal.vue to control the v-modal for Edit and Create Cusotmer form. I am using v-table to list the customers details with button actions index.vue //customer create btn <!-- {{-- CREATE CUSTOMER --}} --> <b-button @click=&

Muaath_Alhaddad's avatar
Muaath_Alhaddad's avatar Muaath_Alh...5yrs agoVue
0
1
CookieMonster's avatar

how to do pagination in snappy pdf?

REMOVED

CookieMonster's avatar
CookieMonster's avatar nickywan12...6yrs agoLaravel
4
1
Last reply by nickywan123 6yrs ago
CookieMonster's avatar

laravel-snappy pdf how to set pagination for more than a certain items?

REMOVED

CookieMonster's avatar
CookieMonster's avatar CookieMons...6yrs agoLaravel
0
1
mvnobrega's avatar

Link lastPage () pagination URL

I am working in a discussion forum and when clicking on the topic the user should be redirected to the last URL of $ post-> links () I'm having a hard time solving this problem. The topics page looks like this: @foreach($rels->sortBy('created_at') as $r) {...} <div class="title"><a href="{{ route('relatoUser', [$r->grupo->slug, $r->slug]

mvnobrega's avatar
mvnobrega's avatar jlrdw6yrs agoGeneral
1
1
Last reply by jlrdw 6yrs ago
shone83's avatar

When I'm using Laravel Vue Pagination I can only load first page of relationship table

I'm using gilbitron/laravel-vue-pagination and I can only fetch first page of relationship table as select or a list if that table is paginated, I can't fetch all data. In controller I return data like this: public function index() { return Settlement::with('town')->paginate(10); } and in Vue I fetch like this: loadSettlements() { axios.get('api/settlement').then(resp

shone83's avatar
shone83's avatar shone836yrs agoVue
3
1
Last reply by shone83 6yrs ago
kevin73's avatar

vuejs - Element UI : problem with pagination component

Hi guys , the image show el-pagination , it's a component of Element-ui , my problem i have to click two times on the button number 2 or the next arrow so that the next button turns blue but the value of current_page is 2 . someone could help me ? Thank you in advance my code : <el-pagination background @current-change="handleCurrentChange" :cur

kevin73's avatar
kevin73's avatar kevin736yrs agoVue
2
1
Last reply by kevin73 6yrs ago
Spiral's avatar

how can make custome pagination for a list

i want to list of objects with pagnation in which will functionality of select per page limit e.g 10,25,100 and will get, searching, and could go to the next page

Spiral's avatar
Spiral's avatar Snapey6yrs agoLaravel
7
1
Last reply by Snapey 6yrs ago
WallyJ's avatar

Livewire Pagination, using mount()

I have followed the instructions in the docs here: https://laravel-livewire.com/docs/mount-method/ to get the results I want from my DB. Livewire Controller <?php namespace App\Http\Livewire; use Livewire\Component; use App\Task; use App\Contact; use App\Contactnote; class Contactshow extends Component { public $contacts; public $tasktext; public $dealId;

WallyJ's avatar
WallyJ's avatar WallyJ6yrs agoLivewire
9
1
Last reply by WallyJ 6yrs ago
ziben69's avatar

Laravel pagination

Hello guys, I have query: $categories = Category::where('visible',1)->orderBy('order', 'asc')->with(['products'])->paginate(3);; in my view: @foreach($categories as $category) <div class="sidebar-box-2"> <h2 class="heading mb-4"><a href="#">{{ $category->title }}</a></h2> <ul> @foreach( $

ziben69's avatar
ziben69's avatar Sti3bas6yrs agoLaravel
1
1
Last reply by Sti3bas 6yrs ago
vlauciani94's avatar

Passing query data in Pagination page

Hello I'm trying to filter homes by Price Ascending, Price Descending, Most Recent, A-Z, Z-A and I've have success with exception to the fact that the queries to not persist after the first page. Can anyone please show me a way to do it? public function index(Request $request) { $query = $request->input('queryOptions'); if($query == 'Price Ascending'){ $prop

vlauciani94's avatar
vlauciani94's avatar tisuchi6yrs agoGeneral
1
1
Last reply by tisuchi 6yrs ago
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 <> '' })

dev-major's avatar
dev-major's avatar sujancse6yrs agoEloquent
1
1
Last reply by sujancse 6yrs ago
t0berius's avatar

eloquent pagination() for relation

Using this query: $user->load(['orders' => function ($query) { $query->with(['product:id,name'])->withTrashed()->latest(); }]); I would like to use a paginator for the retrieved orders. How to do so? I know there's $user->setRelation('orders', relation_query_here); Any suggestions?

t0berius's avatar
t0berius's avatar t0berius6yrs agoEloquent
3
1
Last reply by t0berius 6yrs ago
tehseen's avatar

With paginate how only i get the next and previous button pagination

I am using paginate to display product but the below works fine what i am looking is jut previous and next button only any idea ? {{ $products->links("pagination::bootstrap-4") }}

tehseen's avatar
tehseen's avatar Maracaibo6yrs agoGeneral
4
1
Last reply by Maracaibo 6yrs ago
thebigk's avatar

Pagination: How to get total number of pages?

I'm curious to know what's the right way to get the total number of pages when we use "Pagination". I want to display : Viewing Page 3 of 335. PS: I'm surprised that there is no direct way of getting this count.

thebigk's avatar
thebigk's avatar jlrdw6yrs agoEloquent
8
1
Last reply by jlrdw 6yrs ago
GodziLaravel's avatar

How to add custom attribute to pagination result

Hello , Here the code bellow : $trainings->paginate($limit); returns { "current_page": 1, "data": [ ... ], "first_page_url": "http://___________/api/trainings?xxxxx=xxxxx&page=1", "from": 1, "last_page": 1, "last_page_url": "http://___________/api/trainings?xxxxx=xxxxx&page=

GodziLaravel's avatar
GodziLaravel's avatar Sinnbeck6yrs agoLaravel
2
1
Last reply by Sinnbeck 6yrs ago
Flukedit's avatar

Pagination view issue

This may be a really simple issue, however I can't for the life of me solve it. I am trying to paginate a simple eloquent query, however when I pass the results of the query into my view, I get the following error: Method Tightenco\Collect\Support\Arr::query does not exist. I'm fairly certain that the issue is not in the controller since if I dd() the response I get the followi

Flukedit's avatar
Flukedit's avatar Flukedit6yrs agoLaravel
21
1
Last reply by Flukedit 6yrs ago
mozew's avatar

How to create pagination with ajax?

I have this view called categories/index.blade.php which gets included in index.blade.php: @foreach($categories as $category) <tr> <td>{{ $category->name }}</td> <td>{{ $category->getParent->name }}</td> <td> <form action="{{ route('categories.destroy', ['id' => $category->id]) }}

mozew's avatar
mozew's avatar susanburli...6yrs agoLaravel
5
1
Last reply by susanburling 6yrs ago
connecteev's avatar

Pagination on a Laravel Resource?

How to paginate this with Ajax? This is my Posts API which is consumed by my front-end (in Vue/Nuxt). I am trying to implement an infinite scroll but ->paginate(5) (commented out) does not work. class PostsApiController extends Controller { use MediaUploadingTrait; public function index() { return new PostResource( Post::where([

connecteev's avatar
connecteev's avatar connecteev6yrs agoLaravel
8
1
Last reply by connecteev 6yrs ago
dan3460's avatar

Pagination Problem - probably I'm just dumb

disregards

dan3460's avatar
dan3460's avatar dan34606yrs agoEloquent
5
1
Last reply by dan3460 6yrs ago
raviawasti's avatar

How can i use pagination in laravel vuejs?

Route::get('posts', 'PostController@Allposts'); public function Allposts() { return Post::with('Comment.User','User','Like','Subject') ->where('status',1)->orderBy('created_at','DESC') ->get(); } Here is my view ( vue code in laravel blade) where i am using this localhost /posts API @{{post.user.name}} allpost()

raviawasti's avatar
raviawasti's avatar MThomas6yrs agoLaravel
1
1
Last reply by MThomas 6yrs 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.