2016-05-13 11:08:41 +02:00
|
|
|
<?php namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use DB;
|
2016-07-03 18:11:58 +02:00
|
|
|
use Illuminate\Http\Request;
|
2016-05-13 11:08:41 +02:00
|
|
|
use Log;
|
|
|
|
use Utils;
|
|
|
|
use Closure;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* Class QueryLogging
|
|
|
|
*/
|
2016-05-13 11:08:41 +02:00
|
|
|
class QueryLogging
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @param Request $request
|
|
|
|
* @param Closure $next
|
2016-05-13 11:08:41 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-07-03 18:11:58 +02:00
|
|
|
public function handle(Request $request, Closure $next)
|
2016-05-13 11:08:41 +02:00
|
|
|
{
|
|
|
|
// Enable query logging for development
|
|
|
|
if (Utils::isNinjaDev()) {
|
|
|
|
DB::enableQueryLog();
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $next($request);
|
|
|
|
|
|
|
|
if (Utils::isNinjaDev()) {
|
|
|
|
// hide requests made by debugbar
|
|
|
|
if (strstr($request->url(), '_debugbar') === false) {
|
|
|
|
$queries = DB::getQueryLog();
|
|
|
|
$count = count($queries);
|
|
|
|
Log::info($request->method() . ' - ' . $request->url() . ": $count queries");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|