Files
core/modules/Profiler/Http/Controllers/ProfilerController.php
T

45 lines
1.5 KiB
PHP

<?php namespace Modules\Profiler\Http\Controllers;
use App\Http\Controllers\Admin\Controller;
use Carbon\Carbon;
use Illuminate\Support\Facades\Input;
use Modules\Profiler\Entities\HttpLog;
class ProfilerController extends Controller
{
public function index()
{
$filters = [];
$pastDays = Input::get('pastDays', session('profilerPastDays', 0));
$httpLog = HttpLog::query();
if (is_numeric($pastDays) && $pastDays >= 0) {
$httpLog = $httpLog->where('created_at', '>=', Carbon::today()
->subDays($pastDays));
}
session(['profilerPastDays' => $pastDays]);
if (Input::get('method')) {
$filters[] = 'method';
$httpLog = $httpLog->where('method', Input::get('method'));
}
$displayGrouped = false;
if (Input::get('url')) {
$httpLog = $httpLog->where('url', Input::get('url'))
->with('queries');
} else {
$displayGrouped = true;
$httpLog = $httpLog->groupBy('url', 'method')
->select(\DB::raw('*'), \DB::raw('COUNT(url) as total'), \DB::raw('AVG(time) as time_avg'))
->orderBy('total', 'DESC');
}
$httpLog = $httpLog->paginate(25);
$filter = Input::all();
return view('profiler::index', compact('httpLog', 'displayGrouped', 'filter', 'pastDays'));
}
}