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

tushark1's avatar

Trying to get a collection that is ordered by sum of a relationship column.

Hello, im trying to get a collection of my table customers who have unpaid amounts in a table called payments. This is my query $customers = Customer::where('name', 'like', '%' . $name . '%') ->whereHas('payments', function ($query) { $query->where('payment', 'like', '%unpaid%') ->orWhere('payment', 'like', '%partial%');

tushark1's avatar
tushark1's avatar tushark18yrs agoEloquent
5
1
Last reply by tushark1 8yrs ago
NadeemAkhter's avatar

fetch data on multiple tables.

I have 2 tables one user information and other is images of that user, one user may have more than one images . I want to apply pagination query on data.i apply simple select query but they return one user with one image only dont return the arrray of images

NadeemAkhter's avatar
NadeemAkhter's avatar RamjithAp8yrs agoLaravel
6
1
Last reply by RamjithAp 8yrs ago
DoeJohn's avatar

Paginate Constrained Eager Load?

I have the following relations: Forum hasMany Thread Thread hasMany Post Post belongsTo User There is a page for listing of the forums and I have the following code: $forums = Forum::with(['threads' => function ($query) { // Eager load latest threads $query->approved()->latest() ->with(['posts' => function ($q

DoeJohn's avatar
DoeJohn's avatar DoeJohn8yrs agoLaravel
2
1
Last reply by DoeJohn 8yrs ago
Andreea@Webclix's avatar

Filtering Eloquent on relation

For a new project I am working on a webshop. I have products with a one to many relationship with plant details. Plant details have a column price. I need to order the products on the price of the first detail. If I use a join I get all products ordered by price but I get a new product for each detail relation. I tried: $products = $products->get(); $products = $products->

Andreea@Webclix's avatar
Andreea@Webclix's avatar Andreea@We...8yrs agoEloquent
0
1
JorgeAnzola's avatar

How can get a collection of related models of a related model and paginate it?

Sorry if the title is not really clear, what I meant is: My user hasMany a parent models and each parent model has one child model, so if I do something with eager loading like $parents = Parent::with('child') ->where('user_id', $user->id) ->paginate($this->limit); And my result would be something like: { parent: {

JorgeAnzola's avatar
JorgeAnzola's avatar JorgeAnzol...8yrs agoEloquent
2
1
Last reply by JorgeAnzola 8yrs ago
ddotgrass's avatar

Eager Loading is taking a while

Hi everyone! I just wanted to see if this was an expected result whilst using Eager Loading. I'm having a bit of a slowness issue. Basically, this query: select * from `products` where `products`.`id` in ('1', '2', '3', '4', '5', '7', '8', '11', '14', '17', '18', '19', '20', '21', '22', '23', '24', '33', '35', '86', '101') and `products`.`deleted_at` is null is fine. It doesn'

ddotgrass's avatar
ddotgrass's avatar gregrobson8yrs agoEloquent
6
1
Last reply by gregrobson 8yrs ago
thebigk's avatar

Is it worth Javascriptifying the front-end?

In the build forum with TDD series, I found that the code complexity increases as Vue components are introduced and we basically re-write most of the functionality offered by Blade out of the box (pagination, authentication etc.) If I were to code, I'd only do AJAX for 'favorites' and won't mind page reloading when a user posts a reply or a thread. What does your experience say

thebigk's avatar
thebigk's avatar MikeHopley8yrs agoVue
12
1
Last reply by MikeHopley 8yrs ago
dildo_beggins's avatar

How to paginate a collection?

Probably what I am doing in my code is weird, but eventually I need to paginate my output. And in this case I am not sure how... Here's my code ; public function uploads() { $user_id = Auth::id(); $uploads = Upload::whereHas('user', function ($query) use($user_id) { $query->where('id', $user_id); })->get(); foreach ( $uploads as $upload) {

dildo_beggins's avatar
dildo_beggins's avatar sutherland8yrs agoCode Review
6
1
Last reply by sutherland 8yrs ago
bayramgeldi's avatar

How can I run two functions on same url

Sorry for noob questions. I have pagination and entry fields, they do not work together. Here is screenshot: Screenshot It is controller: <?php namespace app\Http\Controllers; use App\Http\Controllers\Controller; use App\Entry; use Illuminate\Http\Request; /** * */ class pagesController extends Controller { public function getWelcome() { $entry = Entry::inRandom

bayramgeldi's avatar
bayramgeldi's avatar babonday6yrs agoLaravel
7
1
Last reply by babonday 6yrs ago
jofred's avatar

Paginate

I have a query that returns 51 rows, in a view i'm using pagination, if i use ->paginate(1) in the query the pagination doesn't work, it always shows the value of the first row in all 51 pages, if i change the pagination to more than one (->paginate(2)) it works. Anyone knows how to fix this? Thanks!

jofred's avatar
jofred's avatar jofred8yrs agoLaravel
7
1
Last reply by jofred 8yrs ago
makapaka's avatar

How to lazy load table data

Is there a native way to lazy load a large dataset into a table ? I've seen some addons, but I thought vue might have something built in ? If not, any suggestions which is simplest implementation ? I have dataset of over 1000 and more at times to load into a table - i need the endpoint to pull them all back so that I can run some calculations on all the data - so pagination is

makapaka's avatar
makapaka's avatar makapaka8yrs agoVue
0
1
ImeDa's avatar

N days Difference in two date fields

Hi guys, Need help in Eloquent Query. Have two Date fields: delivery_date - format('Y-m-d') created_at created by laravel Need query to get rows, which have the difference between this dates more/less than n days. P.S. Using pagination, so can't get it done using php.

ImeDa's avatar
ImeDa's avatar ImeDa8yrs agoEloquent
4
1
Last reply by ImeDa 8yrs ago
ozza's avatar

Accessing property of a collection

hello, i have a collection which has a dd() like; Pagination {#264 ▼ #total: 2324665 #lastPage: 232467 #items: Collection {#262 ▼ #items: array:10 [▶] +"total": 2324665 +"max_score": null +"took": 70 +"timed_out": false +"scroll_id": "DnF1ZXJ5VGh◀" +"shards": {#263 ▶} } #

ozza's avatar
ozza's avatar ozza8yrs agoLaravel
3
1
Last reply by ozza 8yrs ago
souljacker's avatar

Scout not paginating after defining custom toSearchableArray

I have a Post and a Category model. Each post can have many categories. I'm trying to set my search so the keyword will be searched on posts and on its categories. I achieved this by writing a custom toSearchableArray method on my Post model, but now my pagination is gone. Here's the method public function toSearchableArray() { $array = $this->toArray();

souljacker's avatar
souljacker's avatar souljacker8yrs agoLaravel
0
1
coder_uzb's avatar

How Can I CONCATENATE.

Hi guys. I need concatenate two data.For example. <a>{{ product.name_locale }} </a> export default { data(){ return { favorites:[], pagination:{}, offset:4, lang: en, } }, } How Can I concatenate after name_ lang data

coder_uzb's avatar
coder_uzb's avatar jimmck8yrs agoVue
7
1
Last reply by jimmck 8yrs ago
iGenezys's avatar

Image gallery - Browse a collection 1 by 1

Hi people. I want to do an Image gallery on my laravel project. I want to get all my images randomly, and display them one by one, and have a button that can browse the collection. I have the collection like this : public function random(){ $images = Images::all(); $countImage = Images::count(); $randoImages = $images->random($countImage); r

iGenezys's avatar
iGenezys's avatar iGenezys8yrs agoLaravel
2
1
Last reply by iGenezys 8yrs ago
lara30453's avatar

Lumen Fratcal Testing Error

Hello all, I am testing features in my application and have ran into a problem. I have wrote this feature test: public function a_collection_of_articles_are_returned_paginated() { $user = factory(User::class)->create(); factory(Article::class, 25)->create(); $genArticle = factory(Article::class)->create([ 'title' => 'Some titl

lara30453's avatar
lara30453's avatar lara304538yrs agoTesting
0
1
simonfakir's avatar

Your packages for Laravel Rest API

Dear Laravel community, I wonder if you have List of best practice packages to build a rest API Backend for an SPA. Let's say all the typical problems: Transformers Logging / Debugging E-Mail ACL Pagination JSON Mapping (also for relationships) Translation Management ... Let me know what you would use for a Backend! Simon

simonfakir's avatar
simonfakir's avatar shez19838yrs agoLaravel
2
1
Last reply by shez1983 8yrs ago
nextit's avatar

Paginate relations returns null

Is there anyway we can get relationship data with pagination? If I use 'paginate', all relationship data is null. ForumDiscussion Model public function user() { return $this->belongsTo('App\Models\User', 'user_id', 'id')->select(['username']); } Controller ForumDiscussion::->where('status', 'active') ->with(['user'])->paginate

nextit's avatar
nextit's avatar nextit8yrs agoEloquent
0
1
sreejithvivk's avatar

Page Loads takes more time in laravel

I am using Laravel 5.3 for the project. I have a query which returns more than 1500 records and displays it in the admin console with pagination. The count 1500 may be increased heavily as more applications are submitted. How can i increase the page loading speed faster. Waiting for valuable suggestions.

sreejithvivk's avatar
sreejithvivk's avatar sreejithvi...8yrs agoFeedback
2
1
Last reply by sreejithvivk 8yrs ago
Nervus's avatar

Huge table - how to paginate results

Hello, i want to ask about pagination in laravel. I have middle size table with ~ 5 kk records. I want to use: $pagination = new LengthAwarePaginator( $collection->forPage($page, $perPage), $collection->count(), $perPage, $page ) As u know first parameter is a collection. I read that I should pass as first param whole eloquent data, then laravel slice those collection to

Nervus's avatar
Nervus's avatar jlrdw8yrs agoEloquent
2
1
Last reply by jlrdw 8yrs ago
mlazuardy's avatar

Get Blog Post On User Profile

the next step of making User Profile has complete, but i have a new problem again and again. so i create the show profile method on ProfilesController.php like <?php namespace App\Http\Controllers; use Alert; use Illuminate\Http\Request; use App\Profile; use App\User; use Illuminate\Support\Facades\Input; class ProfilesController extends Controller { /** * Show

mlazuardy's avatar
mlazuardy's avatar mlazuardy8yrs agoLaravel
0
1
mlazuardy's avatar

Make Paginate in Show Method

How to add pagination inside Show Function? i have blog item that have comment and latest article in sidebar, how to use paginate inside it?

mlazuardy's avatar
mlazuardy's avatar ftrillo8yrs agoLaravel
39
1
Last reply by ftrillo 8yrs ago
svdv22's avatar

Best practice/solution for caching filtered results

Hello, I have a page on my website with about a 1000 records that barely change, like a blog. I would like to cache this. The thing is, users can filter and sort these records. A quick calculating thought me that there are 10.000 different filtered sets. So there are 10.000 different ways to filter and order about 1000 records. Question 1 Right now I'm thinking about creating a

svdv22's avatar
svdv22's avatar oraclec2yrs agoLaravel
4
1
Last reply by oraclec 2yrs ago
bojandurmic's avatar

Ran into issues creating a simple search filter

Hi there Laracasts, this is my first post on this forum. I am using Laravel 5.4. So currently I am building a donor management system. I have three tables, Users (which are basically admins), Donors (which are the people who donate) and Donations. The donations table has the following fields: donation_id user_id (the one who created the donation) donor_id (the one who donated)

bojandurmic's avatar
bojandurmic's avatar bojandurmi...8yrs agoLaravel
2
1
Last reply by bojandurmic 8yrs ago
imraj123's avatar

How to paginate the record using multiple tabs

Hi All, I have been used to paginate the list i have four tabs like order, supplier, product, history each has some data if one tab contains more then a ten record i used pagination now my issue is when i paginate the other tabs result or not coming if it has less then ten record can any one help me out in this

imraj123's avatar
imraj123's avatar mgilbertie...8yrs agoLaravel
2
1
Last reply by mgilberties 8yrs ago
douglas_quaid's avatar

Best way to deal with public API routes

I have a question around best practices designing publicly accessible API routes in Spark. I'm using Spark's built-in API to pass along data to my Vue components to be displayed on pages viewable by anyone. The flow looks like this... First, in my HTML I render the component <tasks></tasks> Next, in my component I make an ajax request using Axios axios.get('/api/v1

douglas_quaid's avatar
douglas_quaid's avatar ZetecVan8yrs agoSpark
1
1
Last reply by ZetecVan 8yrs ago
Andreas94's avatar

Problem with the redirect of a search form

Hi guys, I'm stuck in a very stupid problem... I've put a search on my page, But the redirect is incorrect... The search page is: 127.0.0.1:8000/articolo And when you click "send", You will be redirected to: 127.0.0.1:8000/ricerca/Your+Query+exemple As I did instead, I'm redirected to: 127.0.0.1:8000/articolo?cerca=your+query+example, Thus having problems as well with

Andreas94's avatar
Andreas94's avatar Andreas948yrs agoLaravel
6
1
Last reply by Andreas94 8yrs ago
topvillas's avatar

Route Resource Conundrum

I wonder if anybody's encountered a situation like this and if there's a way to get around it. In my web routes I have a staff resource ... Route::resource('staff', 'StaffController'); And in my api routes I have the same thing. The reason being that the web resource index method serves up a blade template the the api resource index will send a list of staff members. Then I can

topvillas's avatar
topvillas's avatar topvillas8yrs agoLaravel
5
1
Last reply by topvillas 8yrs ago
Eldalion's avatar

Video Sharing site

Hi guys, I am kinda new to Laravel (I know some basic things), and I decided to make video sharing app, something like youtube maybe, but not as complex. Like, there would be a homepage with all the videos with pagination, some filters for videos, also users could add their own videos. I was hoping for some pointers from more experienced people here. Or perhaps even some tutori

Eldalion's avatar
Eldalion's avatar jlrdw8yrs agoGuides
1
1
Last reply by jlrdw 8yrs ago
mohbakh's avatar

Cache queries with filter

I'm creating a system that shows users some data with filtering by city, category ... and sorts by some params and has pagination. there are hundreds of cities and categories. If I cache these queries by redis memory goes out of memory? should i use cache or process them normally. Is cache suitable for this one. Thanks.

mohbakh's avatar
mohbakh's avatar mohbakh8yrs agoLaravel
0
1
chrislam's avatar

install vuejs-uib-pagination plugin for Vue.js on laravel 5.4

I'm trying to install vuejs-uib-pagination on laravel 5.4... (https://github.com/sant123/vuejs-uib-pagination) npm install vuejs-uib-pagination Added the following codes to /resources/assets/js/app.js var pagination = require("vuejs-uib-pagination"); Vue.use(pagination); npm run dev Added HTML and scripts var app = new Vue({ el: "#app", data: {

chrislam's avatar
chrislam's avatar pinglam8yrs agoMix
1
1
Last reply by pinglam 8yrs ago
ekrist1's avatar

Vue component inside a foreach loop

I´m building a multipage application and in some of my views I need some reactivity. One option I have thought about is to create a Vue component for each blade view, but it feels wrong. If I have a blade view with a foreach loop of thousands of contacts (with pagination), is it considered a bad practise to add a component within the foreach loop? @foreach($contacts as $contact

ekrist1's avatar
ekrist1's avatar alenabdula8yrs agoVue
2
1
Last reply by alenabdula 8yrs ago
pedroftw's avatar

Getting Paginator pages - Am I doing the right thing?

Hey there, I'm working with pagination and I couldn't find a way to set the current page to whatever I wanted to. Looking at the builder method I got to the following solution: //current page = 1 $page = 3 $products = Product::paginate(10,['*'],null,$page); But in my opinion I just have to send too much information that I'm not actually using to get to the page parameter. Is t

pedroftw's avatar
pedroftw's avatar Jaytee8yrs agoCode Review
1
1
Last reply by Jaytee 8yrs ago
andreich1980's avatar

Relation on two columns

Hello everyone. I have 3 tables in my DB: tables, columns, descriptions. Table hasMany columns. return $this->hasMany(Column::class, 'object_id', 'object_id'); Both tables and columns can have a record in descriptions table. For Table the relation is descriptions.major_id = tables.object_id AND descriptions.minor_id = 0. For Column the relation is descriptions.major_id = co

andreich1980's avatar
andreich1980's avatar andreich19...8yrs agoEloquent
0
1
doobz's avatar

Get component to re-render

I'm stuck at a crossroads with a component I am working on. I have the following component "RecentUpdates" Within it I am passing props down to a few other components, as you can see from the top of the file. My problem is when adding a new post, I can not figure out how to get the correct update object array back and i also can not figure out the correct 'Vue way' to

doobz's avatar
doobz's avatar doobz8yrs agoVue
0
1
ChrisPercival's avatar

Take two -> Joining a group of to their related records

Hi All Sorry to ask again, but I probably did not make myself clear in the first instance. The scenario… I have Posts, Users & Categories. Posts have a many to many relationship with Categories via a pivot table category_ Post & Users also has a many to many relationship with Categories via a pivot table category_user. What needs to happen… A user chooses, from the li

ChrisPercival's avatar
ChrisPercival's avatar Snapey8yrs agoEloquent
1
1
Last reply by Snapey 8yrs ago
aurawindsurfing's avatar

Why is it bad idea to use Request::isJson instead of API route?

Hi, Can someone explain to me in a nutshell why I should not be doing this in my existing laravel app? I want to add json responses to use it in a native app. I have working controllers, routes etc. Now not to rewrite the whole logic I figured that for a simple usage I can do just this: if (\Request::isJson()) { return \Response::json(compact('articles', 'categories

aurawindsurfing's avatar
aurawindsurfing's avatar Snapey8yrs agoRequests
4
1
Last reply by Snapey 8yrs ago
phpMick's avatar

Axios - conditionally append fields.

Hey, I have this Axios patch but I only want to include the last three, if the hyperlink_column isn't null. How can I do this? Thanks, Mick axios.patch('/' + self.table + '/' + self.rowId,{ name: self.name, SQL:self.SQL, area_id:self.area_id, report_type_id:self.report_type_id, mode:self.mode,

phpMick's avatar
phpMick's avatar phpMick8yrs agoGeneral
0
1
jlrdw's avatar

Lengthaware paginator

When ver 5 came out @bestmomo helped me with Lengthaware code, I recently tested it on ver 5.4 it still works good: make a Services folder under app create a file called LengthPager.php Code for LengthPager.php namespace App\Services; use Illuminate\Pagination\Paginator; use Illuminate\Pagination\LengthAwarePaginator; abstract class LengthPager { /** * Create pagi

jlrdw's avatar
jlrdw's avatar lesstenper...2yrs agoGuides
10
1
Last reply by lesstenperfect 2yrs ago
mariante's avatar

Working with PHP in VUE

Hi, I'm trying to work with PHP in VUE... But I'm getting stuck in here... this.$http.get('../api/api.php', {params: {pagination: this.pagination}}) .then(response => { this.$set('items', response.data) this.$set('pagination', response.data.pagination) console.log(items) }) .catch(e => {

mariante's avatar
mariante's avatar KNietzsche8yrs agoPHP
2
1
Last reply by KNietzsche 8yrs ago
ChrisPercival's avatar

Method paginate does not exist

Hi All, I am trying to add pagination to the code below. When I do I get 'Method paginate does not exist' Can someone point out whats wrong? Thanks Chris public function index(Category $category) { /* $listings = ($category->listings->where('published', '=', 2)->paginate(20)); */ $listings = ($category->listings->where('published', '=', 2)); r

ChrisPercival's avatar
ChrisPercival's avatar hakan8yrs agoEloquent
3
1
Last reply by hakan 8yrs ago
toneymutinda's avatar

Chunking results

Hey guys, Am developing a posts application..and in my blog view(where all posts will be displayed), i need to group the results in groups of three, whereby each group will be displayed as a row in my view. So i will end up having rows of three posts each displayed as columns. Mind you, i don't mean pagination.

toneymutinda's avatar
toneymutinda's avatar Snapey8yrs agoLaravel
1
1
Last reply by Snapey 8yrs ago
Azoruk's avatar

Loading more eloquent hasMany relation queries through ajax in Laravel?

On my site, users can post "statuses", and other users can reply/comment on those statuses. On the front page of my site, for example, I have the most liked statuses of the past 3 days displayed. In my HomeController.php: $statuses = Status::where('is_image', 1) ->where('is_mature', 0) ->where('created_at', '>=', Carbon::now()->subHours(168)) -

Azoruk's avatar
Azoruk's avatar jlrdw8yrs agoEloquent
6
1
Last reply by jlrdw 8yrs ago
Scoop7's avatar

Laravel 5.4 + jScroll.js not working(no console errors)

I followed this tutorial with very close detail -> https://laraget.com/blog/implementing-infinite-scroll-pagination-using-laravel-and-jscroll But my the infinite scroll doesn't seem to work - nothing happens when I scroll down through the entire page(even no console errors). I only have one item loaded that is loaded together when the page is loaded. My Controller: public f

Scoop7's avatar
Scoop7's avatar Scoop78yrs agoLaravel
6
1
Last reply by Scoop7 8yrs ago
Crazylife's avatar

How to persist checkbox checked state after div content reload?

I have a pagination for div which during go to another pages the previous checkbox state will lost. var id; $("#list :checkbox").each(function(e){ id = this.id; console.log(this.value); }); Code above can get all the value in a div tag if without button click. If i use the code below, it only shows the data for the page 1. $("#select-all").clic

Crazylife's avatar
Crazylife's avatar dreamxyz8yrs agoGeneral
4
1
Last reply by dreamxyz 8yrs ago
freel's avatar

Filtering, N+1 problem, paginate

Hello, I am working on result display page and have problem with filters. Problem1 I want to display all possible makes and models + display how many results we have. Question1 How can I avoid duplicating query? In my understanding I am not able to use the same result query to get possible makes and models because it have pagination and it shows me results only for this page (1

freel's avatar
freel's avatar freel8yrs agoEloquent
1
1
Last reply by freel 8yrs ago
pranshu's avatar

Getting same records multiple times, how to modify and correct my transformtaion

I have following tables categories contents category_content(pivot with category_id, content_id) images tags contents_tag(pivot with category_id, tag_id) I want to show the contents filtered through the transformer when anyone call the for a single category content. My controller CategoryController.php /** * Display the specified resource. * * @param int

pranshu's avatar
pranshu's avatar pranshu8yrs agoEloquent
0
1
Crazylife's avatar

How to change the paginator arrow button to string "next" and "previous"

I am using this Illuminate\Pagination\LengthAwarePaginator to do pagination // Get current page form url e.x. &page=1 $currentPage = LengthAwarePaginator::resolveCurrentPage(); // Create a new Laravel collection from the array data $itemCollection = collect($items); // Define how many items we want to be visible in each page $perPage

Crazylife's avatar
Crazylife's avatar Prabakaran6yrs agoLaravel
5
1
Last reply by Prabakaran 6yrs ago
Crazylife's avatar

Call to a member function paginate() on array error message

This is my controller. $default= DB::table('products') ........ ->paginate(5)->toArray(); $notDefault= DB::table('products') ....... ->paginate(5)->toArray(); $lists = array_merge($default, $notDefault); $currentPage = LengthAwarePaginator::resolveCurrentPage(); // Create a new Laravel col

Crazylife's avatar
Crazylife's avatar dreamxyz8yrs agoLaravel
4
1
Last reply by dreamxyz 8yrs 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.