\DB::connection()->enableQueryLog();

some sql action...

$query = \DB::getQueryLog();
$lastQuery = end($query);  

dd($lastQuery);

 

php artisan tinker

DB::listen(function($sql){ var_dump($sql);  });

 Inside AppServiceProvider.php add the following to the boot method:

use DB;
use Event;

//..

public function boot()
{
    if (env('APP_ENV') === 'local') {
        DB::connection()->enableQueryLog();
    }
    if (env('APP_ENV') === 'local') {
        Event::listen('kernel.handled', function ($request, $response) {
            if ( $request->has('sql-debug') ) {
                $queries = DB::getQueryLog();
                dd($queries);
            }
        });
    }
}

 

posted on 2015-12-01 15:09  jzfan  阅读(544)  评论(0编辑  收藏  举报