3

I try like this :

public function displayList()
{
    \DB::enableQueryLog();  
    $query = Self::orderBy('program_code')->orderBy('output_code')
                 ->orderBy('account_code')->all();
    dd(\DB::getQueryLog());
    return $query;
}

The result is like this :

[]

It displays an empty array

Is there anyone can help me?

3
  • Have you ever tried Debugbar for Laravel? Commented Jan 11, 2017 at 2:03
  • @KmasterYC, Never before Commented Jan 11, 2017 at 2:54
  • You could listen to laravel db queries as I've mentioned bellow Commented Jan 11, 2017 at 5:03

2 Answers 2

4

Most suitable way to go about this is listen to db queries. You can do

\DB::listen(function ($query) {
    dump($query->sql);
    dump($query->bindings);
    dump($query->time);
})

in your route file. this will dump out executing db queries. But if you want a much cleaner approach you could wrap above listener inside laravel logger like this.

\Log::info(
    \DB::listen(function ($query) {
        dump($query->sql);
        dump($query->bindings);
        dump($query->time);
    })
); 

then the output will be dump into your-app/storage/logs/laravel.log.

NOTE: Keep in mind to remove or comment out above codes as they are for development purpose only.

Further, you could put it in AppServiceProvider like it is mentioned in database transactions

Sign up to request clarification or add additional context in comments.

Comments

1

I suggest you use the package Laravel debugbar: https://github.com/barryvdh/laravel-debugbar. It shows you list of queries executed, and other useful data you want to see.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.