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

MartiX's avatar

Can't retrieve all records from the database with Eloquent or DB

Hi guys, I am facing a strange problem and I can't figure out what's wrong. I have a database with posts table which contains more than 13 000 rows. When I manually try to make an SQL query and select some records, everything works fine. Now when I start the server and try to make a query I can't get all the records. To be specific, I've just got 10 922 records from 13 317. Whe

MartiX's avatar
MartiX's avatar Cronix8yrs agoEloquent
23
1
Last reply by Cronix 8yrs ago
AlexNastase's avatar

Query in accesor

Hi guys, it is ok to use querys in accesors? Example: I want to get the user model instead of the user ID. I will use that accesor in a user pagination page too. The laravel debug bar is not showing the query(s) from the accesor and i'm not sure if should use that accesor or not. In Controller: $conversations = Conversation::with('messages') ->where('user_one', $

AlexNastase's avatar
AlexNastase's avatar AlexNastas...8yrs agoLaravel
4
1
Last reply by AlexNastase 8yrs ago
devamit2018's avatar

current url without paging or page =1

how can i get current URL without pagination or page =1? action='{{Request::URL()}}' will give current url something like http://testpdf.oo/admin/students?q=amit&page=2. after clicking button i need to go http://testpdf.oo/admin/students?q=amit and then perform task.

devamit2018's avatar
devamit2018's avatar Snapey8yrs agoLaravel
4
1
Last reply by Snapey 8yrs ago
codeistalk's avatar

Undefined property: Illuminate\Database\Query\Builder::$map

HI This is the first time I am dealing with API Resources in Laravel. I have create Resource Collection and using it's default definition. Changed nothing. With pagination it's working awesome. When I call /model/{id}, it gives error Undefined property: Illuminate\Database\Query\Builder::$map I have added a screenshot of error too. http://www.openscreenshot.com/#/i/B1ziEDVaf p

codeistalk's avatar
codeistalk's avatar IrsyadAdl6yrs agoEloquent
4
1
Last reply by IrsyadAdl 6yrs ago
octoxan's avatar

How to make this more DRY? Looking for best practice advice.

Let me start off by apologizing that there's not really going to be any code posted by me in this question, I'm just going to have to explain it all verbally. This is both because the sensitive nature of the code, and how long it would take me to "example-ify" it all. Okay, so I have 3 different controllers currently. On the index controller, I accept about 60+ reques

octoxan's avatar
octoxan's avatar martinbean8yrs agoLaravel
1
2
Last reply by martinbean 8yrs ago
alexMafus's avatar

Question about search in eloquent

Hi i want to add in my search implementation the ability to select a checkbox and then to show only the unique players by name and surname so for example if i have a user with name John Doe twice to show me only one here is my code. Player Model public function scopeSearchPlayers($query, $search_id, $search_name, $search_status, $pagination) { return $query->

alexMafus's avatar
alexMafus's avatar jlrdw8yrs agoLaravel
3
1
Last reply by jlrdw 8yrs ago
Aetrox's avatar

homescreen app

Hello, I came to a problem where I can't find a solution to. I try to make a website that needs to work on an iPad and on normal browsers. On the iPad I save the website on the home screen as "app". Many years ago I found this little nice script, which tells the mobile browser to not open new links in browser and to stay in the nice app view on the iPad. (no url bar a

Aetrox's avatar
Aetrox's avatar Aetrox8yrs agoVue
1
1
Last reply by Aetrox 8yrs ago
wontoneesaju's avatar

calling controller function in route

hi i want to call a controller function through my route. Route::get('listcomp',function(){ $page_title="Invoice Management App - List of company"; $companyall=Contapp::viewallcomp(); i want to know how i can do this? i want to create a pagination for this.

wontoneesaju's avatar
wontoneesaju's avatar Vilfago8yrs agoLaravel
11
1
Last reply by Vilfago 8yrs ago
makapaka's avatar

Add count meta to json response

I would like to add a total count records to the json response of my API. I understand that it can be done using a Resource and pagination, however its kind of annoying that I would need to specify each field that needs to be returned. Is there a faster way to just add the meta with total, without pagination - which I guess would have to subsequently wrap the data in data tag,

makapaka's avatar
makapaka's avatar makapaka8yrs agoLumen
2
1
Last reply by makapaka 8yrs ago
beemargarida's avatar

Trying to verify if a request is AJAX

Hi! I am trying to implement pagination with AJAX, and using plain Javascript to do it. The problem is that when I run request()->ajax(), the header "X-Requested-With" isn't set. Here's the code: UserController.php public function showProfile(string $username) { if (!Auth::check()) return redirect('/login'); $this->authorize('list', Project::clas

beemargarida's avatar
beemargarida's avatar beemargari...8yrs agoLaravel
11
1
Last reply by beemargarida 8yrs ago
mcbraga's avatar

Check Checkboxes on VueJS

Hi guys, I'm implementing roles and permissions in my system and I need to get permissions checkboxes checked when user's role has the permission assigned. Any ideas on how to do this? Controller public function index() { $roles = Role::with('permissions')->latest()->paginate(5); $response = [ 'pagination' => [ 'total' => $roles->tot

mcbraga's avatar
mcbraga's avatar mcbraga8yrs agoVue
2
1
Last reply by mcbraga 8yrs ago
pmcrealcor's avatar

Tips for building a FAST Restfull API with Laravel

Hi All, I'm struggling with a "problem" that I'll try to describe shortly (forgive me if my English isn't perfect). I'm currently working with a base-code, developed with Laravel, that I need to optimize. It's an RESTfull API that retrieves JSON, and uses 2 external packages a) to handle API Request (filter, order and pagination) and b) use Fractal Transformer to bui

pmcrealcor's avatar
pmcrealcor's avatar pmcrealcor8yrs agoTips
5
1
Last reply by pmcrealcor 8yrs ago
V9द's avatar

Create Filter query according to parameter using Eloquent

I want to filter products currently I am using below method its working fine. But whenever I want to apply pagination its not work. I tried with LengthAwarePaginator also but there is lot of stuff for me. So Please help and provide better approch if avialable, I am using laravel 5.6 $perpage = "1"; $offset = ($page - 1) * $perpage; $query='SELECT * FR

V9द's avatar
V9द's avatar V9द8yrs agoEloquent
2
1
Last reply by V9द 8yrs ago
n_osennij's avatar

Order by related table field and paginate

I have Articles -> Parts tabels Article.php model public function scopePublished($query) { $query->where('posted_at', '<=', Carbon::now()); } public function scopeNewest($query) { $query->orderBy('posted_at', 'desc'); } public function parts() { return $this->hasMany('App\Part'); } Part.php model public function article() { return $this->bel

n_osennij's avatar
n_osennij's avatar n_osennij8yrs agoEloquent
2
1
Last reply by n_osennij 8yrs ago
jlrdw's avatar

getPdo usage

I have posted a while back a guide on lengthaware paginator: https://laracasts.com/discuss/channels/guides/length-aware-paginator Sometimes for a more complex query I like using regular sql by using laravel's getPdo: Basic usage is : You will probably need a custom lengthaware paginator you will need a count and calculate the current page At top of controller include the DB

jlrdw's avatar
jlrdw's avatar jlrdw7yrs agoGuides
2
1
Last reply by jlrdw 7yrs ago
Spartaque07's avatar

Resource API

Hi all. I want to create api for chat application. Every chat has users and messages relation. I wanna create Resource API for GET /chat/ that will return all chats with auth()->user(). But i wanna have pagination for this chats. And this chat has relation that call as messages, and i wanna have pagination for messages too. Like a inner pagination. Structure of this will be

Spartaque07's avatar
Spartaque07's avatar 96andlgrac...8yrs agoLaravel
2
1
Last reply by [email protected] 8yrs ago
sergionader's avatar

Update records/pagination after reloading the view.

Scenario: I have a view, dealers.blade, that shows in a the contents of a single table. the view has a pagination control,{{$dealers->links()}}, and the controller sends pagianate(10) to the view. The The records of the dealers table are added by importing an excel file. the file upload field and the importer button are in the same blade. Question: say we have 20 dealers

sergionader's avatar
sergionader's avatar sergionade...8yrs agoLaravel
5
1
Last reply by sergionader 8yrs ago
ashraj98's avatar

Eloquent Querying a count

I've got a query in eloquent correctly calculating the count as it should here: $query = A::withCount( ['bs' => function ($query) use ($from, $to) { $query->where(function ($query) use ($from) { $query->whereDate('start', '<', $from) ->whereDate('end', '>', $from);

ashraj98's avatar
ashraj98's avatar ashraj988yrs agoEloquent
0
1
koe's avatar

SEARCH AND ORDER IN RELATED MODELS

Hello, i make API to show Guests with pagination. There is two tables guests and cards guests have name, surname, email, phone and cards have numbers, balance discount and bonus sorting by guests fields work, but i have no idea how to sort it by cards number or balance And guest usualy have one card, but can have more than one. public function index(Request $request) {

koe's avatar
koe's avatar koe8yrs agoEloquent
3
1
Last reply by koe 8yrs ago
nexxai's avatar

Large list of collection items (names) - is there a way to skip to a letter?

We have a large database of names, and we'd like to allow our users to jump to a particular letter in a view. We currently just use basic pagination but that's becoming untenable as the list of names is constantly growing, and by a lot. Is there a way where we can keep pagination (if not, that's OK), but have the ability for our users to skip to a particular letter in the list

nexxai's avatar
nexxai's avatar Snapey8yrs agoLaravel
7
1
Last reply by Snapey 8yrs ago
HighSolutions's avatar

Laravel routes with Vue

Hi, Is there a better way to pass route ID variable than this from code below? I am using Laravel API and fetching it in Vue. API routes // List single product Route::get('product/{id}', 'ProductController@show'); Web.php Route::get('/product/{product}', 'MainController@show')->name('product.show'); MainController@show // Show product details page public function show

HighSolutions's avatar
HighSolutions's avatar Ahimbisibw...8yrs agoVue
1
1
Last reply by AhimbisibweRoland 8yrs ago
kgurleyen's avatar

Search result

do not show other information on the same line in the database. I find the place that is in the search but I want to show zip code? result as Cityname / zip code Table citiy id | name | zipcode | // Search if (Input::filled('q')) { $q = Input::get('q') . '%'; $cacheId .= '.where.name.' . $q; $cities = $cities->where('name', 'LIKE', $q)

kgurleyen's avatar
kgurleyen's avatar bobbybouwm...8yrs agoLaravel
5
1
Last reply by bobbybouwmann 8yrs ago
FrenchFryNinja's avatar

Get the Collection behind a Paginator object

I have a pagination object and need to offer the user the ability to download the collection and its associated objects. Without redoing the query, is there a way to access the LengthAwarePAginator's underlying collection in order to pass it to a method? For example: //Complex and time consuming query sets $orderIds $results = Order::whereIn('id', $orderIds)->paginate(10); /

FrenchFryNinja's avatar
FrenchFryNinja's avatar jlrdw8yrs agoEloquent
8
1
Last reply by jlrdw 8yrs ago
harit's avatar

How to send parameters in paginate function

Hi, In one of the online project I have seen we can pass arguments in laravel paginator by this way. $aData->paginate($aRequest['rowCount'], ['*'], 'page', $aRequest['current']) //where $Data is an eloquent query object But I didn't see any documentation regarding this. I checked the official documentation also, but not seeing such an implementation. Basically I need data ta

harit's avatar
harit's avatar jlrdw6yrs agoLaravel
4
21
Last reply by jlrdw 6yrs ago
redenfm's avatar

Yield and Section but for Vue JS

Hello! Before I start my project, I'm just playing around and work on pagination, deleting records stuff first and I found out that I will have repetitive code over and over for every models. I already done the mixins stuff and right now, it is working. My only problem is I want to make this like @extends on Laravel blade and just put like @yield, @section stuff like that for e

redenfm's avatar
redenfm's avatar redenfm8yrs agoVue
5
1
Last reply by redenfm 8yrs ago
COACHTHEM's avatar

count() method does not return actual number of records when using groupBy() statement.

I have 10 unique records by user_id in my children table. I want to get count of users which has at-least one child so I put group by statement on user_id. below is my code. $count = \App\Children::whereIn('status', ['A','I']) ->groupBy('user_id') ->count(); With this it return me 1 instead of 10. I suspect this might be bug in the Eloquent ORM. I also read i

COACHTHEM's avatar
COACHTHEM's avatar COACHTHEM8yrs agoEloquent
3
1
Last reply by COACHTHEM 8yrs ago
marcelobonifazio's avatar

Relationshiop with paginate and search

I have two tables that relate to each other I need to make a query that takes data in both, and then make a pagination with the result. I have a code like this: return Model::with(['table1']) ->when(($parameters['name']), function ($query) use ($parameters) { return $query->where('model.name','like','%'.$parameters["name"].'%'); }) ->when(

marcelobonifazio's avatar
marcelobonifazio's avatar shez19838yrs agoEloquent
1
1
Last reply by shez1983 8yrs ago
srikanthgopi's avatar

Category in urls

i'm creating an application where i have ArticleCategories and Articles tables. And i have created Articles index page where i can list all the articles according to their categories. For example Category 1 -article1 -article2 -article3 view all Category 2 -article1 -article2 -article3 view all When i click on category1 i want to go to a new page where i can list all the articl

srikanthgopi's avatar
srikanthgopi's avatar srikanthgo...8yrs agoLaravel
2
1
Last reply by srikanthgopi 8yrs ago
sakshamhappy's avatar

How to work Cache system in laravel?

i want to implement Cache system in laravel and using reminder method but still not working, when my database update, delete and create, or if i implement pagination then not working,when i try to change page then i found previous record. #laravel version : 5.5.34 #cache driver : database public function index() { $value = Cache::remember('users', now()->addSeconds(60), f

sakshamhappy's avatar
sakshamhappy's avatar crnkovic8yrs agoLaravel
1
1
Last reply by crnkovic 8yrs ago
jfurnas's avatar

total() not working with get()

Hello there, I am creating a search page that dynamically builds the where() clause based on input provided by a form that has been submitted. In doing so, I have had to use the ->get() method to get the results, and have lost the ability to use total() on my paginate ability. How can I restore this? The code I am working with is; if (!empty($request->parameters) || !

jfurnas's avatar
jfurnas's avatar jfurnas8yrs agoLaravel
2
1
Last reply by jfurnas 8yrs ago
moses's avatar

How can I call view blade laravel in vue component?

My view blade laravel like this : <section class="content"> <product-list :product-data="{{json_encode($products)}}"></product-list> </section> In the view blade call vue component The vue compoponent like this : <template> <div class="box"> ... <div class="box-body">

moses's avatar
moses's avatar ejdelmonic...8yrs agoLaravel
1
1
Last reply by ejdelmonico 8yrs ago
SteveBelanger's avatar

Resource vs ResourceCollection

After watching the video What’s new in Laravel 5.5 - API resources (from 06:40 to 09:20 is the relevant part) , and since I have not dealt with resources and restful API’s before, I have this question : There is this Resource Class which acts like a transformer to take what’s in the model and make it conform to what should be the response to a request. Then, there is ResourceC

SteveBelanger's avatar
SteveBelanger's avatar SteveBelan...8yrs agoGuides
3
2
Last reply by SteveBelanger 8yrs ago
Snapey's avatar

Globally available settings

I've created a Settings model and database table to contain things like email addresses, pagination limits, custom colours - all sorts of settings for the site that I don't want baked into the code. What I want to create is a helper that loads all the settings on first use and can then be accessed anywhere in the application with just a helper like the session helper, eg settin

Snapey's avatar
Snapey's avatar Snapey8yrs agoLaravel
8
1
Last reply by Snapey 8yrs ago
hanif-king's avatar

laravel method not allowed exception with form attribute target="_blank"

My codes result on view woks well and has no error but after i am generating reports of my records from a form submitted from one page and result of the submitted form to another page. it display data well and no error but when i am clicking on pagination button it gives the error of : MethodNotAllowedHttpException in RouteCollection.php line 251: my form : ``page:generateR

hanif-king's avatar
hanif-king's avatar Snapey8yrs agoLaravel
3
1
Last reply by Snapey 8yrs ago
asennett's avatar

lastPage() question for paginate

My goal: When my view loads, I want to be on the last page of the the pagination links. Looking at the docs, it seems like ->lastPage() should get me there but I can't seem to figure it out. I've found a discussion similar to this, but lacking a description of how to accomplish task, only a link to the docs. Which I've read and I guess I'm missing something.

asennett's avatar
asennett's avatar tisuchi8yrs agoLaravel
1
1
Last reply by tisuchi 8yrs ago
littlebox's avatar

paginate and select,options

Hello. Whole day I try to filter by categories in pagination. I read all of google' topics and nothing. So anybody can help me ? I'am new and I learn what I see in web (btw),so I want to display posts with a specific category, which can be may. I have select with multiple options: cat1 cat2 after submit in get I have: myweb.app/x?category=cat1&category=cat2# eg. I selecte

littlebox's avatar
littlebox's avatar littlebox8yrs agoRequests
4
1
Last reply by littlebox 8yrs ago
Xenonth's avatar

How to implement proper redis caching to queries?

Given I have a hotel listing page. And i'm listing 15 hotels in a single page (using pagination). How should I approach caching with the given scenario? Also, how should I handle cache invalidation when a new hotel is added or modified?

Xenonth's avatar
Xenonth's avatar shez19838yrs agoLaravel
1
1
Last reply by shez1983 8yrs ago
mistre83's avatar

L53 - Save/update and back to index with parameters

Hi to all, in my application i have a page where i have some filters and pagination, so the url could be: myapp.dev/orders?id=45&gust=1&page=2 Its a normal page with get parameters. Now, i have some actions where i can update/add new records. So, when i visit this page, i can go to another to update a record myapp.dev/orders/24/edit When the edit is done, i call the upd

mistre83's avatar
mistre83's avatar me_macfly8yrs agoLaravel
1
1
Last reply by me_macfly 8yrs ago
sgtpepper's avatar

Paged Resource Collection not working

I'm building an API and I want to use Laravel's API Resources, but I'm facing a bit of a problem with pagination. As I understand from the docs https://laravel.com/docs/5.5/eloquent-resources if I pass an instance of Illuminate\Pagination\LengthAwarePaginator to a Resource Collection or even a Resource trough the collection method it should build the paginator in a JSON format

sgtpepper's avatar
sgtpepper's avatar aakashdesa...3yrs agoLaravel
12
1
Last reply by aakashdesai-pro 3yrs ago
neflictus's avatar

Ajax issue

Hello I have 2 tables: Children and Media (Spatie MediaLibrary) When I edit the child, there are 2 tabs displayed: one with the child's information, the other - a list of pictures associated with the child. I would like to paginate those pictures, as users might tend to upload too many photos. I would like to use Ajax, and use another method to display the records. public funct

neflictus's avatar
neflictus's avatar neflictus8yrs agoLaravel
3
4
Last reply by neflictus 8yrs ago
makapaka's avatar

Handling 10s of thousands of rows

I have queries that I expect to take a long time - they are 10s of thousands (or 100s) of rows in the DB - how do you handle this ? Obviously pagination of results is step 1, but what if you need to retrieve those rows in order to output to a csv for a client who wants to manipulate them as a spreadsheet ? Any thoughts as to how you resolved this?

makapaka's avatar
makapaka's avatar jlrdw8yrs agoLaravel
1
1
Last reply by jlrdw 8yrs ago
thebigk's avatar

How to paginate an eager loaded relationship?

I wish to eager load 'replies' for any thread being shown to the user. My current approach is to use route-model binding and then separately calling 'replies'. public function(Thread $thread) { $replies = $thread->replies()->paginate(10); return view('Forum.Threads.Show', compact(['thread', 'replies'])); } Then in my view, I simply do foreach($replies as $reply)

thebigk's avatar
thebigk's avatar thebigk8yrs agoEloquent
3
1
Last reply by thebigk 8yrs ago
siusiak1000's avatar

More variables GET (paginate and sorting)

Hey! I have a problem remembering GET. When I have my-domain.pl/shop?page=2 and I click sorting at the price is my-domain.pl/shop?sort=price_desc and I would like moja-domena.pl/shop?page=2&sort=price_desc. I did a search engine and pagination. When I search for something and then go to the next page, the search engine and pagination pass two variables together (moja-domena

siusiak1000's avatar
siusiak1000's avatar morteza8yrs agoLaravel
1
1
Last reply by morteza 8yrs ago
pasiutlige's avatar

Converting SQL query to an Eloquent query builder.

Hello, I am pretty new to Laravel, and can't find a solution to my problem. I've made a SQL query, $likes = DB::select(" SELECT count(likes.post_id) AS AllCount, posts.id, posts.image FROM posts, likes WHERE likes.post_id = posts.id GROUP BY likes.post_id, posts.id, posts.image ORDER BY AllC

pasiutlige's avatar
pasiutlige's avatar pasiutlige8yrs agoLaravel
3
1
Last reply by pasiutlige 8yrs ago
yankeekid's avatar

Appending to existing HTTP Request

I have a complex search form setup on my Laravel site (for searching real estate listings). The form uses the GET method, so I have a long URL string once a search has been performed. The issue is that I want to implement a quick sorting method outside of the original form (using a secondary form with a simple select dropdown just above the results). The problem that I'm runnin

yankeekid's avatar
yankeekid's avatar yankeekid8yrs agoLaravel
2
1
Last reply by yankeekid 8yrs ago
ldcao's avatar

Error when install package wp-eloquent

Hi all, when i install package wp-eloquent, composer show errorr tareq1988/wp-eloquent dev-master requires illuminate/pagination 5.0.* -> s atisfiable by illuminate/pagination[v5.0.0, v5

ldcao's avatar
ldcao's avatar ldcao8yrs agoLaravel
0
1
yudy's avatar

-> orWhereHas Failed Fetch Data From Multiple Tables

I'm using Laravel 5.2 and PostgreSql and deploy on Heroku I have a search form to get data from multiple table >> books, writters, publisher and categories. Here is the controller for the search form public function search(Request $request) { $keyword = $request->input('keyword'); // multiple query from different tables $query = Bo

yudy's avatar
yudy's avatar xmarks8yrs agoGeneral
5
1
Last reply by xmarks 8yrs ago
david001's avatar

Filter data with Laravel

I need help in searching data with laravel i have a form with field date from,to and district input field My form in view @extends('layouts.app') @section('content') <div class="container"> <div class="row"> <div class="col-md-12"> <div class="container"> <div class="panel panel-heading&qu

david001's avatar
david001's avatar david0018yrs agoCode Review
2
2
Last reply by david001 8yrs ago
JaydeepMor's avatar

Paginate link to http.

I used below code for pagination, {!! $list->appends($form)->links() !!} But problem is this redirect to [https] not [http] and i want to [http].

JaydeepMor's avatar
JaydeepMor's avatar JaydeepMor8yrs agoCode Review
2
1
Last reply by JaydeepMor 8yrs ago
randm's avatar

How to get the paganation info in array

I need to display the pagination info only as array. I tried to use toArray() method, but it include the data which I don't really need. So I tried to remove the data key from the array but I don't like the fact that i have to cast the model to array then remove it. I am hoping there is an easier way to do this without having to cast the data then removing it. Here is my code.

randm's avatar
randm's avatar shez19838yrs agoLaravel
1
1
Last reply by shez1983 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.