I am trying to figure out how to execute a raw SQL query, including the data associated with it. Here is what ive got:
\DB::connection()->enableQueryLog(); $query = \DB::getQueryLog(); $lastQuery = end($query);
And here is the result:
array(3) { ["query"]=> string(57) "select * from `table_1` where `field_1` = ? limit 1" ["bindings"]=> array(1) { [0]=> string(34) "xyz" } }
So, how do I get a dump of a full sql query like this (good old fashioned way)?
select * from `table_1` where `field_1` = 'xyz' limit 1
thank
Add this to your routes. Folder:
\Event::listen('Illuminate\Database\Events\QueryExecuted', function ($query) { Log::info( json_encode($query->sql) ); Log::info( json_encode($query->bindings) ); Log::info( json_encode($query->time) ); });
Log :: info () ==> will log an SQL query in the file storage / logs / laravel.log
var_dump () ==> will be displayed in the output API call
Try adding an event listener for the query:
Event::listen('illuminate.query', function($query) { var_dump($query); });
or
$results = User::where('id',$id)->toSql(); dd($results)
Laravel debugbar. Laravel . ( ajax) , , /, . ( TONS , , , , ..)
, Laravel toSql(), . , , . toSql(), , .
toSql()
$foo = Foo::where('bar', 'baz'); $foo_sql = $foo->toSql(); $foo->get();
Source: https://habr.com/ru/post/1653301/More articles:iOS Audio / Video Live Broadcast Solution - iosAngular2 function call from another component - javascriptThe correct way to handle changes in your iOS settings - iosMatlab inheritance polymorphism - polymorphismСохранение листа Excel в виде xml добавляет кавычки вокруг некоторых строк - xmlList of Inno Setup pages with options and screenshots - inno-setupgetting data from jsonp api containing pages - jsonExcel letter library compatible with .net-core - asp.net-coreInferior Shell or UIOP: interacting with the background process - lispAdd Alamofire as a dependency through Swift 3 Package Manager - swiftAll Articles