Skip to content

Instantly share code, notes, and snippets.

@dillinghamio
Last active June 18, 2016 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dillinghamio/1865bc767115aaa57a0e41e6fbcfcfd0 to your computer and use it in GitHub Desktop.
Save dillinghamio/1865bc767115aaa57a0e41e6fbcfcfd0 to your computer and use it in GitHub Desktop.

Laravel Query Dump: count, time, and objects

session('db') using code below, will produce query count, time spent, and the query objects themselves

\DB::listen(function ($query) {
    if(app()->isLocal())
    {
        session()->push('db.queries', $query);
        $queries = collect(session('db.queries'));
        session()->put('db.time', $queries->sum('time'));
        session()->put('db.count', $queries->count());      
    }
});

Add to AppServiceProvider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment