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

michaelnguyen547's avatar

clean up query parameters when using Yajrabox DataTables

I am using Yajra DataTables and it bothers me that query parameters includes junks that I dont want here is an example @ https://datatables.yajrabox.com/fluent/custom-filter and this is the query sent to server https://datatables.yajrabox.com/fluent/custom-filter-data?draw=3&columns%5B0%5D%5Bdata%5D=id&columns%5B0%5D%5Bname%5D=id&columns%5B0%5D%5Bsearchable%5D=true&

michaelnguyen547's avatar
michaelnguyen547's avatar jlrdw7yrs agoLaravel
1
1
Last reply by jlrdw 7yrs ago
matilarab's avatar

Math operations on query

Hey guys I have a table with two columns that have to be divided (A/B) and new calculated every time i reload my web page. I tried placing this query on my controller and als php on my view, but i cannot manage for ($i=0; $i < 0; $i++) { Product::update('Runs' => $products[$i]['Amount']/$products[$i]['Amount_Run']); } anybody has an Idea?

matilarab's avatar
matilarab's avatar matilarab7yrs agoEloquent
2
1
Last reply by matilarab 7yrs ago
manojo123's avatar

Explode Query Builder results

Hello Community I have this query $locales = Local::select("tbl_locales.cc_id", "tbl_locales.nombre") ->selectRaw("GROUP_CONCAT(proveedor_id) as unit_ids") ->join('tbl_local_proveedor_id', 'tbl_locales.id', '=', 'tbl_local_proveedor_id.local_id') ->where("tbl_locales.estado",1) ->

manojo123's avatar
manojo123's avatar realrandya...7yrs agoLaravel
2
1
Last reply by realrandyallen 7yrs ago
axtg's avatar

Fastest query? Count rows in relation after where()

Hi! I'm looking to learn whether the following query is the best way to do what I'm after. Which, from the query I believe becomes clear. Objective: To count all check-ins made today and with a certain status for a set of locations Code: // I start a new query $location->newQuery(); // And do some simple queries on it... $location->where('active', 1); //... //... more (c

axtg's avatar
axtg's avatar BillRiess7yrs agoEloquent
1
1
Last reply by BillRiess 7yrs ago
gnabin01's avatar

Request Query String Parameter not working in Server

I was working with request parameter. In local server request query string parameter is working properly but in Production Server (Centos 7/PHP 7.2.14/Laravel 5.1) it gives different result. I tested using-------- /api/post?limit=20 and page=1 In local Server if i did $request->all() = {limit:20,page:1} In Server $request->all()=api/post Why i am getting this error?

gnabin01's avatar
gnabin01's avatar papa28x45yrs agoRequests
5
1
Last reply by papa28x4 5yrs ago
lara96's avatar

JSON update query runs nothing changes in database?

In my database i have saved some data in post_image table. in that table there is a column image in that i save data like this. [{"1": "[email protected]_1.jpeg"}, {"2": "[email protected]_2.jpg"}, {"3": "[email protected]_3.jpg"}, {"4": "[email protected]_4.jpg"}, {"5": "[email protected]_5.jpeg"}]

lara96's avatar
lara96's avatar lara967yrs agoEloquent
6
1
Last reply by lara96 7yrs ago
konrms's avatar

How to update oracle table using laravel eloquent query

Hi guys, I have created a table called PROG_TITLE with 3 data fields (PR_ID, PR_TITLE and PR_INDEX). I have populated it with values and I want to update PR_INDEX values with 1 if PR_TITLE is not null. How can I do it with eloquent query? The query in oracle is UPDATE PROG_TITLE SET PR_INDEX = '1' WHERE PR_TITLE IS NOT NULL;

konrms's avatar
konrms's avatar konrms7yrs agoLaravel
7
1
Last reply by konrms 7yrs ago
daniel21gt's avatar

Problems with query translation sql to eloquent, laravel 5.5

I try to translate this query select governor_candidate from governor order by governor.id=3 desc; not work governor::orderBy ('id=3', 'DESC'); What I'm I missing of?

daniel21gt's avatar
daniel21gt's avatar daniel21gt7yrs agoEloquent
7
1
Last reply by daniel21gt 7yrs ago
movepixels's avatar

Complicated Query Help

I will try to explain in detail as this is quite difficult. A User can belong to many Area so I have a pivot for that area_user pivot I have a pivot of user_upgrade (user_id, upgrade_id, area_id, expires) An upgrade has a set duration, keep it simple say 7 days hence the expires in the user_upgrade pivot table. And each area is only allowed a specific number of "upgrades&q

movepixels's avatar
movepixels's avatar movepixels7yrs agoLaravel
0
1
Fluber's avatar

Laravel media Library optimize query

Hello. On Main page I have list of shops. On every shop I have a banner. If I have 15 shops on page, I have 25+ query. And most big query this is query of spatie/MediaLibrary. On model Shop I have attribute: protected $appends = ['photo_url']; public function getPhotoUrlAttribute() { if ($this->getMedia('banners')->last()) { return $this->getMedia('banners

Fluber's avatar
Fluber's avatar Braunson7yrs agoLaravel
1
1
Last reply by Braunson 7yrs ago
Deekshith's avatar

Laravel query

Hi everyone, I have two tables namely, user and user_membership users table has the following columns: id,name,email,mobile the user_membrship table has the following columns: id,user_id,started_date,ended_date Now, users renew their membership every year. for example, user table: id name email mobile 1 Deekshith [email protected] 8908908908 and user_membership table have fol

Deekshith's avatar
Deekshith's avatar nikos7yrs agoGeneral
1
1
Last reply by nikos 7yrs ago
Deekshith's avatar

Laravel query

Hi everyone, I have two tables namely, user and user_membership users table has the following columns: id,name,email,mobile the user_membrship table has the following columns: id,user_id,started_date,ended_date Now, users renew their membership every year. for example, user table: id name email mobile 1 Deekshith [email protected]

Deekshith's avatar
Deekshith's avatar douglasaku...7yrs agoGeneral
3
1
Last reply by douglasakula 7yrs ago
fbc's avatar

How do I get a count of how many columns are (or aren't) null in a query?

Basically I have a survey with 30 questions that creates a record in a database. Sometimes people forget they only answered 25% of the survey questions. How do I get a count of how many columns where left 'null' in a query?

fbc's avatar
fbc's avatar sanjayaclo...6yrs agoLaravel
10
1
Last reply by sanjayacloud 6yrs ago
nitinjohnson's avatar

How to dynamically append multiple conditions to Laravel query?

I have an issue that I am facing in Laravel. I am trying to append multiple conditions to a query. In other words I want to add multiple where conditions based on if a particular parameter has value or not. If the parameter has value it should be appended. I am making a product filter and currently I have added product condition and min and max price query conditions. I want bo

nitinjohnson's avatar
nitinjohnson's avatar Sucre6yrs agoLaravel
3
1
Last reply by Sucre 6yrs ago
fbc's avatar

Query all records with a +/- variance of 20% of $xvariable?

How would you make a query of all records with a variance of 20% of values in a column from $xvariable?

fbc's avatar
fbc's avatar martinbean7yrs agoEloquent
2
1
Last reply by martinbean 7yrs ago
knubbe82's avatar

Query problem -> wrong data

I know a User but I need to get Seminars with that User and must use something like this: Seminar::with... This is what I have: $user = User::findOrFail($request->user_id); $seminars = Seminar::with(['users', 'meetings.users'])->whereHas('users', function ($query) use ($user) { $query->where('users.id', $user->id); })->get(

knubbe82's avatar
knubbe82's avatar knubbe827yrs agoEloquent
9
1
Last reply by knubbe82 7yrs ago
Pathum's avatar

Sql join query in Laravel query builder

Here i have this sql query, SELECT distinct candidate.name, `choices`.program FROM ssu.candidate join choices on candidate.option1 = choices.idoptions or candidate.option2 = choices.idoptions or candidate.option3 = choices.idoptions order by name; how this query will be in laravel query builder ?

Pathum's avatar
Pathum's avatar jlrdw7yrs agoLaravel
8
1
Last reply by jlrdw 7yrs ago
Tarasovych's avatar

Reusable query parts

Hello! I want to reuse some query parts in methods below: public function someQuery() { return DB::table('some_table') ->select(...) ->join(...) //I want reuse this join ->join(...) //I want reuse this join ->join(...) //I want reuse this join ->where(...) ->groupBy(...) ->get(); } public function

Tarasovych's avatar
Tarasovych's avatar Snapey7yrs agoLaravel
2
1
Last reply by Snapey 7yrs ago
chris3423's avatar

Query Builder - Paginate AND add custom text to query

I have a problem with the query builder. I use it to make some queries for a Sphinx search. The problem: I want to use the paginate feature but add an option at the end of the query: option max_matches=10000 So the query should be SELECT (...) LIMIT 0,100 option max_matches=10000 Is there a way to do that?

chris3423's avatar
chris3423's avatar Vilfago7yrs agoLaravel
3
1
Last reply by Vilfago 7yrs ago
konrms's avatar

Display query results in table form

Hi guys! I have created a form which accepts a user number input and after submitting it, the user receives some personal data from a local oracle db (which made it to connect to laravel thanks to you!). The query runs fine, but the results appear in list (I use the dd($entries) at the 3rd excerpt). How can I edit my code to appear in a simple table format (simple cells in one

konrms's avatar
konrms's avatar Vilfago7yrs agoLaravel
14
1
Last reply by Vilfago 7yrs ago
eternalchaos520's avatar

Multiple Database on Same Server Join Query

Hi, I had been searching for the solution in the internet for a long time but still I couldn't find the solution, most of the search results is joining on different tables in single database. I need the solution for different DB::Connection left join and get the query results. Please noted that I only want to view the results only, no any CRUD required. Moreover, all databases

eternalchaos520's avatar
eternalchaos520's avatar jonnywilli...4yrs agoLaravel
7
1
Last reply by jonnywilliamson 4yrs ago
fbc's avatar

Query help "syntax error, unexpected 'foreach' (T_FOREACH)"

Trying to make a query to display the last 5 values of a table. In my controller I have: $thismonthsconsumption = Consumption_history::orderBy('end_period', 'desc')->take(5)->get(); $elecconsump_chart->dataset('My Consumption', 'line', [ @foreach ($thismonthsconsumption as $consumption) {{$consumption->units_consumed}}, @endfo

fbc's avatar
fbc's avatar fbc7yrs agoEloquent
6
1
Last reply by fbc 7yrs ago
ifarooq's avatar

Laravel Eloquent limit and offset is being added automatically to count query

Laravel Eloquent limit and offset is being added automatically to count query. Limit and offset is being added automatically to my following query although I am not adding any limit and offset into it. $total_trashed_records=$query_records_trashed->onlyTrashed()->count(); Below is are my queries. $fields=["id", "first_name","last_name",&quo

ifarooq's avatar
ifarooq's avatar cvairlis2yrs agoLaravel
4
3
Last reply by cvairlis 2yrs ago
theUnforgiven's avatar

Pivot Data on Query

I have a basic query to get all users: return User::orderBy('name') ->where('id', '!=', auth()->user()->id) ->get(); But I also have a company_user pivot table, which within the above query I need to pass this in, allowing the query to show the 4 rows in the pivot table. This is then saying there are 4 users associated with t

theUnforgiven's avatar
theUnforgiven's avatar theUnforgi...7yrs agoLaravel
10
1
Last reply by theUnforgiven 7yrs ago
Deekshith's avatar

Laravel hasmany relationship query

I have two tables User table and user membership table user membership table consists every year data for a user. Example: User table id name 1 Deekshith User Membership Table: id user_id started_at ended_at 1 1 2018-01-01 2018-12-31 2 1 2019-01-01 2019-12-31 So it has one to many relation My question is how to fetch recor

Deekshith's avatar
Deekshith's avatar Deekshith7yrs agoGeneral
11
1
Last reply by Deekshith 7yrs ago
Moenchfracht's avatar

Select columns from query

Hi, I have a query with relations: \App\Products::where('xfs', '>',10)->with('users')->get() I know the select method to get only specific columns. But this only returns columns from the Products model. How can I get specific columns from the User model? Thanks!

Moenchfracht's avatar
Moenchfracht's avatar Moenchfrac...7yrs agoLaravel
8
1
Last reply by Moenchfracht 7yrs ago
nickdavies07's avatar

SQL Query Builder - Grouping and Ordering

Think this is more an SQL query but here goes... I need to get a set of results from one of my tables to output to a chart. The chart needs to show "the number of concerns for each month, for this academic year (1st Sept 2018 to 31st August 2018)". The returned result should look something like: | month | total | |-----------|-------| | September | 15 | | Octob

nickdavies07's avatar
nickdavies07's avatar nickdavies...7yrs agoLaravel
3
1
Last reply by nickdavies07 7yrs ago
Fluber's avatar

Laravel do one query

I have model post. I use this package: https://github.com/cyrildewit/eloquent-viewable I have accesor in model post: protected $appends = ['views']; public function getViewsAttribute() { return $this->views()->count(); } In blade when I foreach my posts: @foreach($posts as $post) Views: {{ $post->views }} {{ trans_choice('trans.views', $post->views) @endf

Fluber's avatar
Fluber's avatar Mithrandir7yrs agoLaravel
5
1
Last reply by Mithrandir 7yrs ago
comms_express's avatar

Using an array in an SQL query

So i have this form where a user can search for product data and can filter it by ProductGroup. The user has to be able to select more than one ProductGroup. How would i be able to add this to query? Example The data passed through from the form is this $searchData = [ 'product_group' =>[ 0=>'test1', 1=>'test2', 2=>'test3'

comms_express's avatar
comms_express's avatar jlrdw7yrs agoEloquent
5
2
Last reply by jlrdw 7yrs ago
Axeia's avatar

Can I recycle my earlier query to the WhereNotIn to avoid duplicates?

Hello, I have a 404 page for when people enter a /name in the url that isn't in my database it lists the names of the closest matches. This is the code for finding results somewhat matching the given input. //Escapes underscores and percentage signs in case user enters these $likeEscapedName = $this->escapeLike($name); //Try to find by ma

Axeia's avatar
Axeia's avatar Axeia7yrs agoEloquent
0
1
iqlas's avatar

Append query string to URL

I am working on multi lingual application in Laravel (5.7) I have a middleware Locale which is applied for all the web routes group and it checks if the locale is set for application and sets if not. Here to make the URL unique for each language, I want to add query string ?lang=en or as required. I used the following in Locale middleware public function handle($request, Closur

iqlas's avatar
iqlas's avatar jlrdw7yrs agoLaravel
4
1
Last reply by jlrdw 7yrs ago
movepixels's avatar

Query Help

I need some assistance as how to get a list of available dates. Try to explain what I need so hope this comes across clear. I build an array of the next 10 weeks (Sun thru Sat) that will get be used as a select input of dates to select from. Now each date(week) has a limit of 25 spots so I have a pivot table of event_user which holds the event_id, user_id, date, (other fields

movepixels's avatar
movepixels's avatar jlrdw7yrs agoEloquent
1
1
Last reply by jlrdw 7yrs ago
jhutto's avatar

Converting mysql to laravel query

I have a mysql query that I can not figure out how to translate into Laravel query in controller The 355 will be a variable as soon as I can get this to run. SELECT somascourseregistrations.id, `CourseID`, `StudentID`, `StatusID`, `TA`, `DropDate`, `TuitionType`, (`ClassFee`+`HomeOfficeFee`+`MaterialsFee`) AS TotalTuition, (SELECT SUM(`PaymentAmount`) AS TotalPayments FROM `som

jhutto's avatar
jhutto's avatar jhutto7yrs agoGeneral
4
1
Last reply by jhutto 7yrs ago
NadeemAkhter's avatar

class function use in where query

in my user class i have function isOnline(), it return boolean public function isOnline() { return Cache::has('user-is-online' . $this->id); } i want to query get all online members . how i use this function inside query ?? User::where('here i need code which check isOnline return true or false')->get();

NadeemAkhter's avatar
NadeemAkhter's avatar NadeemAkht...7yrs agoLaravel
2
1
Last reply by NadeemAkhter 7yrs ago
kokarat's avatar

Can I Custom query on resources?

I need to use resources feature without custom tools but I need to use a custom query it possible to do that?

kokarat's avatar
kokarat's avatar yaroslawww5yrs agoNova
3
1
Last reply by yaroslawww 5yrs ago
jhutto's avatar

mysql nested query... How to make it work in laravel query

I've been trying to get this to work for quite awhile now and just need some help. I'm trying to write this query into a controller but can not figure out the format. SELECT `CourseID`,`StudentID`, `ClassFee`,`HomeOfficeFee`,`MaterialsFee`, (`ClassFee`+`HomeOfficeFee`+`MaterialsFee`) AS TotalTuition, SUM(`PaymentAmount`) FROM `somascourseregistrations`, `somasstudentclasspaymen

jhutto's avatar
jhutto's avatar jlrdw7yrs agoLaravel
1
1
Last reply by jlrdw 7yrs ago
uccdev's avatar

Laravel Pagination - changing the page makes my query vanish?

So I'm writing a page using Laravel that calls data from my database. First, lemme describe & show you my code, with the problem stated below it. The database returns all its data in the form of a paginated table. The user is given five fields and a submit box. Every field is optional, so they can be as specific as they like in their query. If no values at all are called, t

uccdev's avatar
uccdev's avatar uccdev7yrs agoLaravel
2
1
Last reply by uccdev 7yrs ago
acidjazz's avatar

Eloquent belongsToMany query help

Hey everyone, I'm trying to specify a belongsToMany relationship with a setup where with : Content -> Licenses -> Orgs So say a simpler approach in my Content model I have these two relationships: public function licenses_public() { return $this->belongsToMany(License::class) ->whereDoesntHave('orgs'); } and public function licenses_private() { retu

acidjazz's avatar
acidjazz's avatar acidjazz7yrs agoEloquent
0
1
Drfraker's avatar

How to speed up this sql query

In my application ( which is multitenant) I have a query that can take up to 10 seconds depending on the number of rows in the database for a given office. I'd like to speed this up but I'm not sure how to do it. The table for this query "notes" is quite large and has around 800,000 rows in it. Additionally, the note_text on the notes table can be quite large. Here's

Drfraker's avatar
Drfraker's avatar jlrdw7yrs agoEloquent
5
1
Last reply by jlrdw 7yrs ago
ssquare's avatar

Help needed to convert update query to updateOrCreate

My current code: $existing = Student::where('name_last', $student['name_last']) ->where('name_first', $student['name_first']) ->where(function($query) use ($student) { if (array_key_exists('phone_preferred', $student) && !empty($student['phone_preferred'])) { $query->where('phone_preferred', $student['phone_preferred']); }

ssquare's avatar
ssquare's avatar ssquare7yrs agoEloquent
8
1
Last reply by ssquare 7yrs ago
Majeed's avatar

HOW To Use where clause in egar loading eloquent Query in Laravel

I'm working on ACL system. during working on system I've face a challenge. Here is my query , How can i use where clause in this query... $this->roles()->with('permissions')->get()->pluck('permissions')

Majeed's avatar
Majeed's avatar Snapey7yrs agoLaravel
6
1
Last reply by Snapey 7yrs ago
jmatchett123's avatar

SQL query not working in laravel

Hi, This query works absolutely fine in sql SELECT * FROM lessons LEFT JOIN (SELECT * FROM progress WHERE user_id = '5' GROUP BY user_id) progress ON lessons.lesson_id = progress.lesson_id However when I try to convert it to laravel, it doesn't work. Am I doing anything wrong? $data = DB::table('lessons') ->leftjoin( DB::raw("SELECT * FROM progress WHERE user_id = '5'

jmatchett123's avatar
jmatchett123's avatar jlrdw7yrs agoLaravel
5
1
Last reply by jlrdw 7yrs ago
Ford555's avatar

my query and conversion to Eloquent

hi, in laravel5.6 i have a table contacts with several fields, one of them is created_at (timestamp) with format 2018-10-04 14:25:04 if there are 3 contacts the day 2018-10-04, 7 contacts the day 2018-10-05 and only 1 contact the day 2018-10-06 i need a query to know number of contacts by day in sql the correct query is: SELECT COUNT('id') as total_contacts, DATE_FORMAT(create

Ford555's avatar
Ford555's avatar Ford5557yrs agoLaravel
6
1
Last reply by Ford555 7yrs ago
GTHell's avatar

Laravel export eloquent query as report?

So I have a beautiful query and would like to export it to A4 or possibly excel but with header, logos date just like typical invoice you see everyday. How would I do that?

GTHell's avatar
GTHell's avatar GTHell7yrs agoLaravel
4
1
Last reply by GTHell 7yrs ago
ThinkingMan's avatar

Eloquent Query Return to View breaks after 3 in array

I am not sure if the title is exactly correct but I have a query in my controller which performs a count on 3 data fields from two tables and is then supposed to return them to a dashboard view. I can get this to work when I have two of the three results post to the view but when I send all three to the view I get an error "Undefined variable: ordercounttoday (View: C:\xa

ThinkingMan's avatar
ThinkingMan's avatar jlrdw7yrs agoEloquent
2
1
Last reply by jlrdw 7yrs ago
popcone's avatar

Change pagination URL query string

Hello, Is there a way to parameter name 'query' to another name? $resuls->nextPageUrl() generates search?query=test&page=2 How can we change this to tosearch?s=test&page=2

popcone's avatar
popcone's avatar habeebnet7yrs agoCode Review
4
1
Last reply by habeebnet 7yrs ago
Mubeenali's avatar

Query failed getting error laravel 5.6

hi i want to run the query "SELECT * FROM users WHERE author = 'mubeen' AND name LIKE '%$veriable%' i am getting error like Object of class Symfony\Component\HttpFoundation\ParameterBag could not be converted to string.. Please help me $query = $request->query; $users = User::where([ ['author', 'superAdmin'],

Mubeenali's avatar
Mubeenali's avatar Snapey7yrs agoEloquent
10
1
Last reply by Snapey 7yrs ago
mikail10000000's avatar

Where clause does not work in group by query builder

Hi, the query works fine without where clause, but currently it returns empty result return DB::table('orders') ->select( DB::Raw('COUNT(orders.id) as order_count'), DB::Raw('DATE(orders.created_at) day') ) ->where('created_at','>' , Carbon::parse($request->start)) ->where('created_at ','<' ,Carbon::

mikail10000000's avatar
mikail10000000's avatar globals7yrs agoEloquent
3
1
Last reply by globals 7yrs ago
Gabotronix's avatar

Create an object of arrays from each result of a query

Hi everybody, I have a query which takes the "name" parameter of all product categories in my backend, what I want to do is create an object of empty arrays where each empty array key is the name of the product category: public function getProductCategoriesArray() { $productcategories = ProductCategory::pluck('name')->get(); return response()-&

Gabotronix's avatar
Gabotronix's avatar lostdreame...7yrs agoGeneral
1
1
Last reply by lostdreamer_nl 7yrs ago
kshitizmittal's avatar

Convert MySQL raw query to Eloquent statement

select ed.*,pr.punch_in,pr.punch_out,pr.date,roster.week_off from (select * FROM employeedetails WHERE status = 'Active') as ed LEFT JOIN (SELECT * FROM `punchreports` where date = '".$currentDate."') as pr on ed.emp_id = pr.emp_id LEFT JOIN (SELECT * FROM rosters WHERE month='December' AND year='2018') as roster on ed.emp_id = roster.emp_id How to convert this query

kshitizmittal's avatar
kshitizmittal's avatar kshitizmit...7yrs agoEloquent
2
1
Last reply by kshitizmittal 7yrs 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.