This commit is contained in:
Stefanescu Mihai
2026-03-18 13:32:36 +02:00
parent 6ad100d331
commit 274f6a378e
22 changed files with 1217 additions and 42 deletions
+3 -27
View File
@@ -2,15 +2,17 @@
namespace App\Http\Controllers;
use App\Http\Controllers\Concerns\ParsesDateRange;
use App\Models\Website;
use App\Services\AnalyticsQueryService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\View\View;
class DashboardController extends Controller
{
use ParsesDateRange;
public function show(Request $request, Website $website): View
{
$this->authorize('view', $website);
@@ -35,30 +37,4 @@ class DashboardController extends Controller
'active' => AnalyticsQueryService::activeVisitors($website),
]);
}
private function parseDateRange(Request $request): array
{
$range = $request->get('range', '7d');
$to = Carbon::today();
$from = match ($range) {
'today' => Carbon::today(),
'7d' => Carbon::today()->subDays(6),
'30d' => Carbon::today()->subDays(29),
'90d' => Carbon::today()->subDays(89),
'custom' => Carbon::parse($request->get('from', Carbon::today()->subDays(6)->toDateString())),
default => Carbon::today()->subDays(6),
};
if ($range === 'custom' && $request->has('to')) {
$to = Carbon::parse($request->get('to'));
}
if ($from->gt($to)) {
[$from, $to] = [$to, $from];
}
return [$from, $to];
}
}