Mohsen Mahoski
Mohsen Mahoski

Reputation: 492

Display all SQL executed in Eloquent in laravel 5.4

i have this route in my web.php:

Route::get('task' , function(){
   return App\Carsoul::all();
});

this code return:

[{"id":12,"image":"1502286679.jpg"},{"id":14,"image":"1502287112.jpg"}]  

i want to display query that return above result so i add this code before Route:

Event::listen('illuminate.query', function($query){
  var_dump($query);
});  

expect to return like:SELECT* FROM 'carsouls' ...
but return same result:

[{"id":12,"image":"1502286679.jpg"},{"id":14,"image":"1502287112.jpg"}] 

what is the mistake?

Upvotes: 0

Views: 1177

Answers (1)

FULL STACK DEV
FULL STACK DEV

Reputation: 15951

Hi if you want to show the query as a string in Eloquant you can try

Model::orderBy('id','ASC')->toSql() it returns complete query.

Hope this helps

Upvotes: 1

Related Questions