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

imJohnBon's avatar

Fractal Paginating Subresources

I'm currently working on integrating Fractal into an API Lumen project. However, I have a question about paginating embeds. Let's say we have API response for books that also has a sub-embed for the books authors: { "data": [ { "id": 11 }, { "id": 12 }, { "id": 13 }, { "id": 14 }, { &

imJohnBon's avatar
imJohnBon's avatar joshgallag...8yrs agoGeneral
2
1
Last reply by joshgallagher24 8yrs ago
HeinZawHtet's avatar

Sort result with custom function and paginate

Hi, I want to sort results with custom function and want to paginate the result. I try this. EG : $posts = Post::paginate(3)->sortBy(function ($post) { // custom sort here }); It 's work . But when i show pagination in views with $posts->render();. It said "Method render does not exist". How to sort with custom function and paginate properly. Is there any

HeinZawHtet's avatar
HeinZawHtet's avatar zachleigh10yrs agoEloquent
3
1
Last reply by zachleigh 10yrs ago
inventsimple's avatar

Testing HTML tables in views

I'm fairly new to PHPUnit testing so please forgive me if this is an obvious question. I want to test a page with a html table that displays items 10 at a time. I also want to make sure that pagination is working. Is there a way to do this or am I kind of missing the point of unit testing? Thanks in advance.

inventsimple's avatar
inventsimple's avatar inventsimp...10yrs agoTesting
0
1
Asser90's avatar

Quiz - Get unique questions based on inputs - Point in right direction.

Hi there. Its almost against my principles to ask on discussionboards whats probably allready answered somewhere out the great www. However this time google and a few more searchengines could not help me. I'm currently (first time using laravel) trying to develop a quiz system. The quizzes works the way that it has to generate a quiz based on parameters. Either it has to be a q

Asser90's avatar
Asser90's avatar Asser9010yrs agoLaravel
0
1
iMsIdZz's avatar

Need Help for Forum

i am using one to many relationship but i confuse how to get comments in each post for example my post hasMany comments and comment belongsTo post in my view i am fetching all with pagination but it won't work help me what to i do don't suggest for riari forum

iMsIdZz's avatar
iMsIdZz's avatar StefanBaue...10yrs agoLaravel
1
1
Last reply by StefanBauer 10yrs ago
ratiw's avatar

vuetable - data table simplify!

I have been working on Vue.js table component for my own work for quite sometime. And I think it's good enough to share and hoping it might be helpful to the others. Please check it out at https://github.com/ratiw/vue-table Any comment and suggestions are very welcome. http://s20.postimg.org/lf470bkd7/vuetable_short.gif No need to render the table yourself One simple vuetable

ratiw's avatar
ratiw's avatar locdh418yrs agoVue
54
1
Last reply by locdh41 8yrs ago
jbowman99's avatar

Submit form on keyPress enter

I have a select2 search function and when a user presses enter within the search box the the field will be populated with the first result pulled from the search request. I would like upon keypress enter to submit the form. js for the select2 looks like this: $(document).ready(function () { $(".js-search-menus").select2({ multiple: true,

jbowman99's avatar
jbowman99's avatar jbowman9910yrs agoGeneral
2
1
Last reply by jbowman99 10yrs ago
Melcus's avatar

Vue.JS Vue-Tables Laravel Relationship

I am using https://github.com/matfish2/vue-tables with Laravel. This is the vue code Vue.use(VueTables.client, { compileTemplates: true, highlightMatches: true, pagination: { dropdown:true, chunk:5 }, filterByColumn: true, texts: { filter: "Search:" }, datepickerOptions: { showDropdowns: true } }); new Vue

Melcus's avatar
Melcus's avatar Melcus9yrs agoVue
10
1
Last reply by Melcus 9yrs ago
chimit's avatar

Sorting by the count of related models

I have two models: class Photo extends Model { public function likes() { return $this->morphMany('App\Like', 'likeable'); } } class Like extends Model { public function likeable() { return $this->morphTo(); } } Here is a method for getting the paginated and ordered list of photos: $photos = Photo::orderBy($req

chimit's avatar
chimit's avatar chimit10yrs agoEloquent
0
1
sebastian.virlan's avatar

Html block or JSON from ajax response?

Hi guys, how is best practice to return data from a controller through ajax? html block JSON If html block is easy, because you only append the response to a container, but if JSON how do I build the html? Also I have and pagination. There must be somehow to get the html from a partial because I don't think is a good idea to have html in js variables.

sebastian.virlan's avatar
sebastian.virlan's avatar Reached10yrs agoGeneral
5
3
Last reply by Reached 10yrs ago
sameermalikrp's avatar

App\Http\Controllers\WorkerController::worker() does not exist

Error found on pagination 1)works fine for the first page( localhost/worker/search ) other than that if I select 2,3,4.... ( localhost/worker/search?page=1)page it shows " ReflectionException in Route.php line 264: Method App\Http\Controllers\WorkerController::worker() does not exist " and the field value(in this case search string erases on every page load) routes.ph

sameermalikrp's avatar
sameermalikrp's avatar sameermali...10yrs agoLaravel
6
1
Last reply by sameermalikrp 10yrs ago
sameermalikrp's avatar

App\Http\Controllers\WorkerController::worker() does not exist

Error found on pagination 1)works fine for the first page( localhost/worker/search ) other than that if I select 2,3,4.... ( localhost/worker/search?page=1)page it shows " ReflectionException in Route.php line 264: Method App\Http\Controllers\WorkerController::worker() does not exist " and the field value(in this case search string erases on every page load) routes.ph

sameermalikrp's avatar
sameermalikrp's avatar sameermali...10yrs agoLaravel
0
1
schir1964's avatar

Foundation 6 Presenter for Paginator

Illuminate\Pagination class works really well but only has Presenters for Bootstrap. I decided to take a crack at making a Presenter for Foundation 6 and amazingly it only took about an hour of actual code changes (a few more for reading and analyzing the code). Anyway, I copied the following two files to my App directory and renamed them and made the necessary changes for imp

schir1964's avatar
schir1964's avatar schir196410yrs agoTips
0
1
mallorca's avatar

Call relationship in route?

Hi Artisans, I followed Jeffs series on activity feed. Right now, I have in my route this: $userevent = User::with('event')->get(); Then in my view, I have something like this: @foreach ($userevent as $user) @foreach($user->activity as $event) @include ("activity.type.{$event->name}") @endforeach @endforeach Instead of do

mallorca's avatar
mallorca's avatar Augustus10yrs agoLaravel
5
1
Last reply by Augustus 10yrs ago
jbowman99's avatar

Select Box changed to a Input text search

I have a select box that is populated by an ajax call to a get method, I would like to change the select box to an Input and autocomplete textbox. Ajax Call $(document).ready(function () { $(".js-search-items").select2({ placeholder: 'Find an Item', allowClear: true, ajax: { type: 'POST',

jbowman99's avatar
jbowman99's avatar hdsavani8yrs agoLaravel
5
1
Last reply by hdsavani 8yrs ago
tomirons's avatar

Is there a way to simplify this?

I'm trying to reduce the amount of work here, cause this may be something I use across my application quite a lot. <script> var page = 0; $(window).on('hashchange', function() { if (window.location.hash) { var page = window.location.hash.replace('#', ''); if (page == Number.NaN || page <= 0) { return false;

tomirons's avatar
tomirons's avatar willvincen...10yrs agoCode Review
2
1
Last reply by willvincent 10yrs ago
todi's avatar

Calling withTrashed() inside global scope fails

Hi, I'm trying to call withTrashed() on the QueryBuilder within a global scope. This is what the global scope looks like: public function apply(Builder $builder, Model $model) { [... some stuff not related to the $builder or $model ...] return $builder->withTrashed(); } I already check if the scope actually gets called. I use a universal index functi

todi's avatar
todi's avatar elias5yrs agoEloquent
3
2
Last reply by elias 5yrs ago
davestewart's avatar

Reducing code duplication on resource controllers

Bit of a long post, but hopefully an interesting area (and hopefully one which has been solved before) so I would appreciate the input :) I'm mainly a front end guy, and if there's one thing I hate about back end code, it's the amount of repetition of mundane tasks. I find this especially apparent with the resource controller lifecycle. The way I see it, you have 7 core tasks,

davestewart's avatar
davestewart's avatar TiagoRodri...6yrs agoLaravel
1
1
Last reply by TiagoRodrigues 6yrs ago
MN1's avatar

Using Laravel to display movie collection DB w filters?

Hi All, Front-end developer here looking to make a database challenge for myself: I'm thinking of creating a database of my disc-based movie/tv collection (I have some DVDs, some Blu-Rays, most are movies, some are TV shows) and connecting to some movie-based API to get the duration in minutes and year of release, and display that on a one-page site with sorting functionality a

MN1's avatar
MN1's avatar kevinbui6mos agoLaravel
18
1
Last reply by kevinbui 6mos ago
bin0's avatar

Laravel whereHas Relationship Query General Error: 25

Okay, so first I'll explain what I'm trying to do here. So picture this: there is a products page and inside this there are multiple products. On the backend, each product has a stock. Think of a stock as in a real store, you go to the back, and that is where you may have multiple sizes of this same product. So since each product has a stock, I'm trying to filter the size to th

bin0's avatar
bin0's avatar bin010yrs agoLaravel
1
1
Last reply by bin0 10yrs ago
Joeri's avatar

Laravel infinite scroll with position redirect.

Hey, I'm looking around for a infinite scroll in my posts feed that works with laravel pagination. So when the user is near the bottom the next page appends on the bottom. I found some jQuery plugins that could manage this like infinite-scroll & jScroll. The point is I want to have the option to redirect the users to the post or comment they created, so lets say the comment

Joeri's avatar
Joeri's avatar JoeriAben10yrs agoTips
2
1
Last reply by JoeriAben 10yrs ago
eventhq's avatar

Query params being ignored when integration testing a JSON API

I'm trying to build integration tests for a JSON API where the response is paginated. Calling the endpoint with postman shows the endpoint paginates just fine if I add ?limit=1&page=2 to the URL. I can get the integration tests working fine with no query params but if I add any query params at all, they get completely ignore. An example test is: $this->get('http://api.ev

eventhq's avatar
eventhq's avatar eventhq10yrs agoTesting
0
1
Corbin's avatar

Has anyone built threaded comments with franzose/ClosureTable package? Just looking to hear about your experience.

I'm just about to attempt to create my own threaded comments system. I'm wondering if anyone could share their experience building a threaded comment system and more particularly experience with: https://github.com/franzose/ClosureTable/tree/master/src/Franzose/ClosureTable I'm wondering if I'm going to have to build the closure tables on my own, or hopefully I can use this pac

Corbin's avatar
Corbin's avatar myrdsrn10yrs agoLaravel
3
1
Last reply by myrdsrn 10yrs ago
ElpsySec's avatar

Simple Route Params Binding With Vue.js

I have a table component that relies on pagination to display a chunk at a time. While I am using the paginate() feature, I am not using laravel to update the route because I'm using vue-resource. I was wondering if there was a simple way to bind a data property to a route paramater such as page. I'm also passing in sort and search parameters in the route. I've looked at vue-ro

ElpsySec's avatar
ElpsySec's avatar infernobas...10yrs agoVue
13
1
Last reply by infernobass7 10yrs ago
rvpwebdev's avatar

Maincontroller does not exist while trying to paginate

Hello, I ran into this weird "bug" today. I developed my website locally, everything works fine over there. Today I pulled the project on my dev server, at first everything seemed okay but when I tried to use my pagination, I ran into this strange RelectionException: "Class App\Http\Controllers\Maincontroller does not exist". Screenshot of the stacktrace in

rvpwebdev's avatar
rvpwebdev's avatar premsaurav10yrs agoLaravel
3
1
Last reply by premsaurav 10yrs ago
AcceoMKT's avatar

Pass data accross component using vueify

Hi, i am making a pagination for a table using AJAX. At first i did it all in the same component using a main.js with vueify to import it. However it would be nice to use the pagination again for other type of table so i wanted to extract it in a pagination component. But, i'm not exactly sure how to do it. Table and Pagination are both children of the Vue app in main.js so usi

AcceoMKT's avatar
AcceoMKT's avatar topvillas10yrs agoVue
1
1
Last reply by topvillas 10yrs ago
midascodebreaker's avatar

How to Properly Cache Querries with Offset?

Hi I know Cache Works by Setting a Key But If i Use Pagination in line with Cache let say i assign one key to the cache. And Check the key everytime if it has a key It Really Seems useless coz the key is being replace by another querries every now and then during a request for example this is the first request select count(*) as aggregate from `products` select * from `products

midascodebreaker's avatar
midascodebreaker's avatar pmall10yrs agoLaravel
1
1
Last reply by pmall 10yrs ago
ashleywnj's avatar

Vue and Paginate

Hi - I have been trying to add pagination to a table that is using Vue, I found a simple example that I have been attempting to build upon, however i works with Vue 0.11 but not with Vue 1.0 The two examples are below. Any recommendations appreciated. This does not work with Vue 1.0.14 https://jsfiddle.net/ashleywnj/65n3yLeL/ This works with Vue 0.11.10 https://jsfiddle.net

ashleywnj's avatar
ashleywnj's avatar stereoscie...10yrs agoVue
3
1
Last reply by stereoscience 10yrs ago
chrisml's avatar

How to cache Laravel paginate()?

Hey guys, I have an Event model which has many Status'. I am paginating the statuses and using render() in the view to generate page links. I'm also caching these statuses like so: // $id is the event ID $statuses = Cache::remember('statuses_' . $id, 3, function() use ($event, $sort) { return $event->statuses() ->with('comments') ->latest()

chrisml's avatar
chrisml's avatar jadamec5yrs agoLaravel
8
1
Last reply by jadamec 5yrs ago
keyur's avatar

How are people creating back end admin forms

I'm trying to create about 20-30 back end forms to manage data in the tables (for an existing laravel application). I have a fair amount of more advanced features, search, editable grids, sorting, pagination, saved searches. Wondering how other people are generating these back end admin screens. I have looked at tools like Scriptcase, PhpRunner, PhpMaker. These are OK, some a

keyur's avatar
keyur's avatar keyur10yrs agoGeneral
0
1
PoncetheLion's avatar

One to many relationship in a somehow big table - slow performance

I have this table source_data with source_data_details as its child with one to many relationship source: ======= id name create_by create_datetime status source_field: ============= id source_id (FK from source.id) name data_type max_length default_value special_field status source_data: ============ id source_id (FK from source.id) create_datetime generated_code source_dat

PoncetheLion's avatar
PoncetheLion's avatar vtalbot10yrs agoEloquent
1
1
Last reply by vtalbot 10yrs ago
enriqg9's avatar

How to query by a hasMany relation and paginate?

I have a Company model which has a ManyToMany relationship Trade. I am working on a Company Directory but I would like to be able to filter Companies by Trade, for example, select all the Companies that have a trade of 1 and 4 and then make a pagination object. Right now I am doing my query like this: Trade::with('companies')->whereIn('id', Request::get('trades'))->get()

enriqg9's avatar
enriqg9's avatar enriqg910yrs agoLaravel
1
1
Last reply by enriqg9 10yrs ago
jlmmns's avatar

Query filter on Polymorphic model?

Hi all, I'm trying to paginate polymorphic Contacts (Business or Person). The problem is, I can't find a way to add a query filter on the Person model. I want to get all Contacts, be it a Business or Person, but a Person CANNOT belong to a Business. (for this result set) My goal is to have an overview of all Contacts, and paginate them. But I need to exclude the People that bel

jlmmns's avatar
jlmmns's avatar jlmmns10yrs agoEloquent
1
1
Last reply by jlmmns 10yrs ago
toby's avatar

Loading HTML via Ajax

Hello everyone, I've got a dataset which I display as a table; currently, this table is plain HTML (Blade): {!! Form::open(['route' => 'dataset.index', 'method' => 'GET']) !!} <table> <thead> <tr class="pagination-row"><td colspan="4"><span class="pagination">{!! $entries->render() !!}</span>

toby's avatar
toby's avatar trevorg10yrs agoVue
1
1
Last reply by trevorg 10yrs ago
Dyasis's avatar

Method render does not exist...

I'm trying to do a simple pagination but I am getting the following error: ErrorException in Macroable.php line 81: Method render does not exist. In my controller I have: $providers = \App\Providers::paginate(5); return view('dashboard.index', compact('providers')); in my view I am calling {!! $providers->render() !!} what am I missing here? thanks

Dyasis's avatar
Dyasis's avatar ChrisArter9yrs agoLaravel
29
1
Last reply by ChrisArter 9yrs ago
alpha's avatar

How to paginate a collection?

Hello guys, I am having a hard time solving pagination problem. Are there a way to paginate a collection? or how can i paginate a post while ordering it by created at? Post::where('slug', $slug)->firstOrFail()->minipost()->orderBy('created_at', 'desc')->get(); This is the code that i use to retrieve the latest minipost for the post. But 1 post can have more then 15

alpha's avatar
alpha's avatar alpha10yrs agoEloquent
5
1
Last reply by alpha 10yrs ago
david001's avatar

Call to a member function render() on array

I want to generate pagination links but i got error "Call to a member function render() on array" my controller public function imageAlbum(){ $albums = Album::orderBy('id','ASC')->where('type','=','0')->where('status', '=', '1' )->paginate(1); // dd($albums); if(count($albums) > 0): foreach ($albums as $value) { // d

david001's avatar
david001's avatar martinbean10yrs agoLaravel
3
1
Last reply by martinbean 10yrs ago
hfalucas's avatar

Using cursors with fractal to paginate content

So I am using the fractal package to build an API and recently having trouble with pagination. I'll try to give a basic but accurate example of my code. The Cursor implementation is working fine and all the problem is in the query I think. So basically I have this: public function trainers($query, Request $options) { $howMany = $options->get('howMany', 20); $

hfalucas's avatar
hfalucas's avatar hfalucas10yrs agoLaravel
0
1
Mushr00m's avatar

Paginate Eloquent collection

Hi, I need to paginate an Eloquent collection (so after DB call). But from what I've read doing Paginator::make() doesn't exists anymore. I'm a little confused of how I should do it ? Examples would be nice. My aim is to still do $items->appends(Request::only(['type', 'size']))->render() in my view and be able to keep the inputs in the pagination links and display them as

Mushr00m's avatar
Mushr00m's avatar Kaakati4yrs agoEloquent
17
3
Last reply by Kaakati 4yrs ago
babusharif's avatar

Still many things to cover

How can i use dynamic url instead of Route::get('/api/messages', function(){ return \App\Project\Message::all(); }); like Route::get(inbox/{user}/{applicantid}); how to use {user}, and {applicantid}) in this.$http.get('/api/messages',function(messages){ this.$set('messages', messages); how to use php variable and eloquent in directives, how to use

babusharif's avatar
babusharif's avatar JoeDawson10yrs agoVue
3
1
Last reply by JoeDawson 10yrs ago
adelin's avatar

vue-router/laravel routes + vue-components/laravel's blade

Hello there! I have an app that i need to make but the problem is that in time it could become quite big. So now, because of that i have 2 options: i either use old school laravel route + blade templates and use vuejs for stuff like: sorting, filtering, pagination, searching, ... i use vue-router and load all pages as components (and their sub-components) at once (using: brows

adelin's avatar
adelin's avatar simondavie...10yrs agoVue
3
1
Last reply by simondavies 10yrs ago
saqueib's avatar

Limit the result from eager loaded relation

I am building an API which needs below post data with many eager loaded relation. Here is how I have tried, its working but I can't limit the number of replies, adding ->limit(1) is not giving any effect. How I can optimize query is so slow (taking 5 sec in local machine) since its returning huge data. return $postRepo->with([ 'replies' => function($q) {

saqueib's avatar
saqueib's avatar pmall10yrs agoEloquent
1
1
Last reply by pmall 10yrs ago
ufodisko's avatar

ErrorException in LengthAwarePaginator.php: Division by zero

I have a comments list with a per_page input field that allows users to show more comments on the page via ajax. By default, it's set to 50 But when I try to change it, say to 25, I get this errors in the developer's console POST http://localhost/r2/public/posts/per_page 500 (Internal Server Error) And in the Network tab, I can see this error ErrorException in LengthAwarePag

ufodisko's avatar
ufodisko's avatar ufodisko10yrs agoLaravel
0
1
kmangaraj's avatar

Getting Paginated Data for eager loaded query

Hi, I am able to do this. return $this->program ->with(['subjects' => function ($q) { $q->paginate(10); }])->findOrFail($id); { "program": { "id": 1, "program_name": "Ut non qui.", "slug": "ut-non-qui", "program_description": "Co

kmangaraj's avatar
kmangaraj's avatar kmangaraj10yrs agoEloquent
3
1
Last reply by kmangaraj 10yrs ago
sebastiansulinski's avatar

Paginator

Is there an easy way of swapping the default LengthAwarePaginator contract implementation so that it can still be used with the default methods on the Eloquent\Builder? By the look of it Builder uses concrete implementation: public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null) { $page = $page ?: Paginator::resolveCurrentPage($pageName)

sebastiansulinski's avatar
sebastiansulinski's avatar jlrdw10yrs agoEloquent
3
1
Last reply by jlrdw 10yrs ago
jlrdw's avatar

Sorting

Earlier this answer was given for sorting $sortedCards = $cards->sortBy(function($card ) { return $card->number; }); I don't see how this would work if thousands of results with pagination. Because in this case you already have an array of results.

jlrdw's avatar
jlrdw's avatar jlrdw10yrs agoEloquent
4
1
Last reply by jlrdw 10yrs ago
toLucky's avatar

Combination of take and paginate

Can someone tell me how to limit the output of a query builder while still useing pagination???? In my controller: $max_count = 100; $query_builder->get()->take($max_count); return view('model.index', [ 'model' => $query_builder->paginate(10), ... ] In my /model/index.blade.php HTML - blah blah {!! $model->render() !!} Thanks

toLucky's avatar
toLucky's avatar jlrdw10yrs agoEloquent
1
1
Last reply by jlrdw 10yrs ago
Sonu's avatar

How we can Limit over Search Query

I want to know that there is any way to limit the search query. Actually i have 10 Lakh records in Db. For example if a user search chicken then its search from all data base and generate the pagination. so its generate alot of pages. I want to just search on 2000 records only. How can i do that. Here is my search function $input = trim(Input::get('diet_search')); $exp = ex

Sonu's avatar
Sonu's avatar jlrdw10yrs agoGeneral
8
1
Last reply by jlrdw 10yrs ago
davorminchorov's avatar

Multipagination in one view

Hey, I have this requirement where I have to implement 2 different pagination links for 2 different tables in one page. For that to work, I need to change the query string name from page=N to something else like table_one_page=N and table_two_page=N but that does not work. I mean, I can change the names by using $this->user->paginate(10)->setPageName('users_page=N');

davorminchorov's avatar
davorminchorov's avatar Ruffles10yrs agoLaravel
5
1
Last reply by Ruffles 10yrs ago
duc91bk's avatar

Search Results Paginate

I creat pagination: Route::post('search',[ 'as'=>'search.post', 'uses' => 'SearchController@getSearchPost' ]); class SearchController extends Controller { public function getSearchPost(Request $request) { $key=$request->key; $articles = Article ::orderBy('created_at','desc') ->where('title', 'like', "%$key%") ->select('

duc91bk's avatar
duc91bk's avatar duc91bk10yrs agoLaravel
10
1
Last reply by duc91bk 10yrs 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.