0

In my app/config/app.php file, I have turned on 'debug'=>true. I have tried

//run eloquent functions
$allMessages = Messages::with('User')->whereIn('conv_id',$conv_id)->orderBy('created_at','aadesc')->take(10);

$q= DB::getQueryLog();
dd($q);

but it returns an empty array. So I guess it is useless to do end($q) as suggested.

I have also tried the accepted answer to a question and added it to the end of my routes file but nothing happened. I'm still new to Laravel and need some guidance. Thank you!

Community
  • 1
  • 1
John Evans Solachuk
  • 1,953
  • 5
  • 31
  • 67

1 Answers1

2

A popular method is to monitor the Event for Eloquent, and output any queries run on the database as you are going along:

Event::listen('illuminate.query', function($query, $params, $time, $conn) 
{ 
    dd(array($query, $params, $time, $conn));
});

$allMessages = Messages::with('User')->whereIn('conv_id',$conv_id)->orderBy('created_at','aadesc')->take(10);

That will output the query that is run.

Another option is to use a Laravel4 Debugger package, which automatically shows you the queries run: https://github.com/barryvdh/laravel-debugbar

Laurence
  • 58,936
  • 21
  • 171
  • 212