Linked Questions

12 votes
4 answers
35k views

Laravel 5 Eloquent: How to get raw sql that is being executed? (with binded data) [duplicate]

Im trying to figure out how to get the raw sql query being executed including the binded data in it. Here is what ive got: \DB::connection()->enableQueryLog(); $query = \DB::getQueryLog(); $...
Raheel Hasan's user avatar
  • 5,872
0 votes
1 answer
289 views

get raw sql query in laravel [duplicate]

In User model I define relation : \App\User::where('id' ,1)->toSql(); it return select * from users where id = ? how can I get full query including params? Also I define relation with post model: ...
Paritosh Mahale's user avatar
0 votes
0 answers
52 views

Optimizing laravel model by using SQL [duplicate]

I am taking sum of all orders by week, month and year. My code is like this: $current_day = Order::whereDate('created_at', Carbon::today()) ->where('order_status', 'Complete') ...
Azamat's user avatar
  • 11
204 votes
15 answers
354k views

How to Get the Query Executed in Laravel 5? DB::getQueryLog() Returning Empty Array

I'm trying to view the log for a query, but DB::getQueryLog() is just returning an empty array: $user = User::find(5); print_r(DB::getQueryLog()); Result Array ( ) How can I view the log for this ...
Arsen's user avatar
  • 3,581
165 votes
9 answers
168k views

In PHP with PDO, how to check the final SQL parametrized query? [duplicate]

In PHP, when accessing MySQL database with PDO with parametrized query, how can you check the final query (after having replaced all tokens)? Is there a way to check what gets really executed by the ...
JB Hurteaux's user avatar
  • 4,478
23 votes
5 answers
98k views

Does Laravel's toSql() method mask ids? (column value being replaced by question mark)

I'm trying to debug some SQL queries that I'm doing in a testing suite. Using the following debugging code: \Log::debug(User::first()->jobs()->toSql()); The SQL that prints out is: `select * ...
Zach Smith's user avatar
  • 8,695
16 votes
8 answers
15k views

Laravel 4 SQL log / console

Is there something similar in Laravel that allows you to see the actual SQL being executed? In Rails, for example, you can see the SQL in console. In Django you have a toolbar. Is there something ...
Slava V's user avatar
  • 17.1k
2 votes
5 answers
10k views

Call to a member function toSql() on integer

I have a code: $update= DB::table('Appraiser_commands')->where('cycle_id', $cycleid)->where('user_id',$userId)->update(['mode' => $mode,'Appraiser_commnd'=>$json])->toSql(); ...
Shanu k k's user avatar
  • 1,241
0 votes
1 answer
5k views

Laravel how to change date format in the list

We are retrieving the list from the database which is having date. We want to display it in different format. Suppose 10 Nov, 2014. Here is my Code Trail1: $dropDown = Events::lists(DATE_FORMAT(...
vvr's user avatar
  • 466
6 votes
2 answers
2k views

How to use Eloquent ORM's getQueryLog() outside of Laravel?

I've been trying to figure out a way to log SQL queries from Eloquent ORM which I'm using within Zend Framework 1. I came across getQueryLog() method called in this manner: $queries = DB::getQueryLog(...
Martyn's user avatar
  • 6,177
0 votes
1 answer
1k views

Get raw sql query from belongsToMany relationship

How do I get raw sql like "SELECT * FROM table WHERE id = 1" from belongsToMany. public function users(){ return $this->belongsToMany('App\User','user_projects','project_id','user_id'); } i ...
sby05922's user avatar
2 votes
1 answer
2k views

PHP & Laravel: ConvertingVARCHAR value to FLOAT in query

I have stored in my table two fields lat and long, these columns have the datatype of VARCHAR Now in Laravel I have the following variables: $ne_lat = 21.405122657695813; $ne_lng = -102....
Daniel's user avatar
  • 376
2 votes
1 answer
623 views

Laravel jQuery auto-complete speed

I am using Laravel. The autocomplete speed is slow. I know that it might be due to the fact that I have a lot of information my database. I have a total of 38432 rows in the table. But I'm sure ...
user avatar
0 votes
2 answers
1k views

Laravel query builder always fetches null data

I am quite new to Laravel, especially when it comes to retrieving things from a database. After reading their documentation about query builder, I found a section that shows example code to do exactly ...
user avatar
-3 votes
2 answers
2k views

Laravel like query not working

Laravel "like" query doesn't work. For example, the query is as follows; $result = Sports::where('name', 'LIKE', '%'.$name.'%') for example $name= 'football'; If I use $result->toSql(); ...
Fly Goshawk's user avatar
0 votes
2 answers
937 views

Lumen Database Queue first job always failing Allowed memory exhausted

I have a very odd situation where I set up a job to run in my Lumen database queue and all but the first job is processed. I do keep getting this particular error: [2017-12-12 22:07:10] lumen.ERROR: ...
David Jarrin's user avatar
  • 1,705
1 vote
1 answer
677 views

NOTORM how to know sql query

in notorm documentation we know to get sql query use (string) $table but i didn't get any result when use it. $data = array('name'=>'testing','age'=>'25') $result = $db->table->insert($...
Dedi Ananto's user avatar
0 votes
2 answers
735 views

Retrieved records base on its created_at, yesterday to the start of the current month

I'm trying to retrieved records base on its 'created_at' timestamp column, where yesterday is the start date and retrieved records until to the start of the current month $h_msg1 = m_chat_history::...
Juliver Galleto's user avatar
-1 votes
1 answer
387 views

Extraction of data from database by criteria with Laravel

Hi I tried to write some query where i want to extract emails from accounts by relevant criteria. So for example if i want to send email by city i can choose city and sent email to people from this ...
Adrian's user avatar
  • 5
1 vote
0 answers
316 views

show all subjects offered by a student using laravel eloquent

I have done one-to-many relationships but when I loop through it in my view only one subject displays even when I have more than one subjects. This is what I have done in my controller $broadsheet = ...
Goldmines's user avatar
0 votes
2 answers
234 views

Filter Pivot table conditionally with inverse relation - Laravel 5

I have roomConfigurations table like bellow, id roomTypeID hotelId Then Hotels table is like this id hotelNeme Then Users table like this id userId userName passwd Then hotel_user (Pivot) table ...
Lahiru Maduranga's user avatar
0 votes
0 answers
264 views

How can I write this raw mysql left join query using Laravel eloquent?

I'm converting my web application to Laravel framework but I have a specific problem trying to write a particular raw SQL query in Laravel eloquent. Here's the query: What I've tried so far: $cp = ...
Okafor T Kosiso's user avatar
0 votes
1 answer
204 views

mysql query in laravel suddenly not working

I have a laravel app that's been working for 2.5 years on a hosted site. Today an auto complete field started generating an exception on Connection.php > SQLSTATE[42S22]: Column not found: 1054 ...
pfa's user avatar
  • 135
1 vote
1 answer
231 views

Laravel controller query

I have a laravel project with Laravel Framework 5.8.38 I try to convert mysql query: SELECT b.name as business_location_name , u.first_name as cashier_first_name , u.last_name as cashier_last_name , ...
fionka's user avatar
  • 23
0 votes
2 answers
169 views

Laravel 5.4 query builder having issues with groupBy

I'm trying to convert this query to query builder in Laravel 5.4: SELECT oc.id, oc.name, oat.user_id, p.first_name, p.last_name FROM oauth_clients oc LEFT JOIN ...
Matt Larsuma's user avatar
  • 1,476
0 votes
1 answer
198 views

SQLSTATE[42000]: Syntax error or access violation when i use DB::raw("CAST(SUM(amount) AS INTEGER)")

Hello Guys i have the code to get the invoices from my database. its work on localhost, But on online server it get me error. the code is: $users = User::whereHas('subscriptions', function ($q) { ...
Hasan Hatem's user avatar
1 vote
1 answer
152 views

Laravel 5.2 select data unknown variable

My function in controller for get data when user search ajax. This is my code: $receiptNum = Request::get('receiptNum'); // echo $receiptNum = 123456 DB::connection()->enableQueryLog(); $q = DB::...
ching's user avatar
  • 132
0 votes
1 answer
100 views

Laravel error when get data from mySQL using groupBy

I want to get Data from mySQL where its only get 1 id_product,so when there is 2 data with same id_product value.. its only get the first one.I have tried the query in mySQL and its work, the query is ...
justinus andreas's user avatar
0 votes
0 answers
142 views

Laravel 5.6 querying related tables to filter results based on multiple columns from both the tables

Hello guys I am working on a project build using laravel 5.6, I want to filter results in search, based on conditions that applies to different columns from both the tables. I have two tables one is ...
AK Devs's user avatar
  • 34
1 vote
1 answer
53 views

Which join is actually used behind the join() of laravel?

I just want to know that which join will be used behind the scenes in Laravel join(). Either it is leftjoin(), rightjoin() or innerjoin() ? For example: What join will be used here actually? $...
Kaleem Shoukat's user avatar
1 vote
1 answer
82 views

Improve SQL queries speed

I'm using MySQL and i have schema like: |------------|-------------|------------|--------------| | cities |category_city| categories| companies | |------------|-------------|------------|-----...
pwnz22's user avatar
  • 469
0 votes
1 answer
102 views

orderBy method on laravel 5

I want to sort the records using orderBy method in desc order on the created_at field. But my code doesn't take my orderBy method. Don't know what is the problem. Given below is my code. public ...
cathy123's user avatar
  • 543
0 votes
1 answer
79 views

Unable to Print Raw SQL

I've tried various options. I just want to get the raw sql for this; $payments = Payment::select('Vendor ZIP')->whereIn('Vendor ZIP', $postcodes)->get()->toArray(); I've tried; //this dd(...
mikelovelyuk's user avatar
  • 4,092
0 votes
0 answers
76 views

Laravel 7 show insert query

I want to insert data into my DB, some of my data are stored, some others are not stored : the dd() shows me that all data are ok : array:9 [▼ "_token" => "...
David's user avatar
  • 427
0 votes
0 answers
50 views

How do I query data from a pivot table in Laravel 7 [duplicate]

UPDATE: I changed my code reading some of the suggested threads. Now the function in my controller is: public function search (Document $document, Request $request) { $from = $request -> ...
Maya's user avatar
  • 1
0 votes
1 answer
37 views

Laravel MySQL: translating SQL queries to Laravel Eloquent

I am trying to get time availability for my scheduling system. I know how to do it with plain SQL query but I am having trouble translating the query to Laravel Eloquent. My query is like the one ...
Kim Carlo's user avatar
  • 1,221
-2 votes
3 answers
46 views

Laravel Eloquent how to use && or AND inside single WHERE clause [closed]

I am trying to make a query using Eloquent Model in Laravel. My original query does not work Query1::where('Course_ID', '=', $request->FLA) ->where('Date', '=', Carbon::today()) I would like ...
John Lyons's user avatar
0 votes
1 answer
37 views

Search HasManyThrough

I want to display all kelompoks that have the same kantors based on search keyword. i had 3 tables Kantor id nama Gugus id nama id_kantor Kelompok id nama id_gugus here is my ...
Rznboth's user avatar