Skip to content

Instantly share code, notes, and snippets.

@sarkarshuvojit
Created January 19, 2018 05:53
Show Gist options
  • Save sarkarshuvojit/4f6a7c11863251bf6830bf58948a36fd to your computer and use it in GitHub Desktop.
Save sarkarshuvojit/4f6a7c11863251bf6830bf58948a36fd to your computer and use it in GitHub Desktop.
Log all queries in a log file - Laravel
<?php
namespace App\Http\Middleware;
use Closure;
class QueryLog
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
\DB::connection()->enableQueryLog();
$response = $next($request);
// Perform action
$queries = \DB::getQueryLog();
\Log::useDailyFiles(storage_path().'/logs/queries/query.log');
\Log::info($queries);
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment