Tuesday, 13 September 2016

Unknown

Debug and log query using DB::enablequerylog() in laravel

Debugging query in laravel

    Steps for Logging query in Log file
  1. First use DB;
  2. DB::enableQueryLog();
  3. you can dd(DB::getQueryLog())
  4. To get last executed query use - end(DB::getQueryLog())
     DB::enableQueryLog();
       // Run your queries
       // ...

       // Then to retrieve everything since you enabled the logging:
       $queries = DB::getQueryLog();
       foreach($queries as $i=>$query)
       {
           Log::debug("Query $i: " . json_encode($query));
       }

       Log::debug('Last query is :'.$last_query = end($queries););
  


In next post we will learn more about relationship methods

  1. with()
  2. has()
  3. whereHas()
  4. withCount()

Thank you.

Unknown

About Unknown -

Freelancer,Entrepreneur,Aesthetic bodybuilder.

    Knows :
  • Laravel Framework
  • Ionic Framework + Angular JS
  • Bootstrap
  • CSS
  • Jquery

Subscribe to this Blog via Email :