diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 3e75b68..04de6db 100755 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -34,22 +34,14 @@ class AdminController extends Controller //Statistics of the number of clicks and links public function index() { - $userId = Auth::user()->id; - $littlelink_name = Auth::user()->littlelink_name; + return view('panel/index'); + } - $links = Link::where('user_id', $userId)->count(); - $clicks = Link::where('user_id', $userId)->sum('click_number'); - - $userNumber = User::count(); - $siteLinks = Link::count(); - $siteClicks = Link::sum('click_number'); - - $lastMonthCount = User::where('created_at', '>=', Carbon::now()->subDays(30))->count(); - $lastWeekCount = User::where('created_at', '>=', Carbon::now()->subDays(7))->count(); - $last24HrsCount = User::where('created_at', '>=', Carbon::now()->subHours(24))->count(); - $updatedLast30DaysCount = User::where('updated_at', '>=', Carbon::now()->subDays(30))->count(); - $updatedLast7DaysCount = User::where('updated_at', '>=', Carbon::now()->subDays(7))->count(); - $updatedLast24HrsCount = User::where('updated_at', '>=', Carbon::now()->subHours(24))->count(); + public function stats() + { + $user = Auth::user(); + $userId = $user->id; + $littlelink_name = $user->littlelink_name; $topLinks = Link::where('user_id', $userId) ->whereNotNull('link') @@ -57,35 +49,63 @@ class AdminController extends Controller ->orderBy('click_number', 'desc') ->take(5) ->get(); + + // Combine queries for user-specific data + $userLinksData = Link::where('user_id', $userId) + ->selectRaw('COUNT(*) as links, SUM(click_number) as clicks') + ->first(); + + if ($user->role == 'admin') { + + // Combine queries for site-wide data + $siteLinksData = Link::selectRaw('COUNT(*) as siteLinks, SUM(click_number) as siteClicks') + ->first(); + + // Combine queries for user counts + $userCounts = User::selectRaw('COUNT(*) as userNumber, + SUM(CASE WHEN created_at >= ? THEN 1 ELSE 0 END) as lastMonthCount, + SUM(CASE WHEN created_at >= ? THEN 1 ELSE 0 END) as lastWeekCount, + SUM(CASE WHEN created_at >= ? THEN 1 ELSE 0 END) as last24HrsCount, + SUM(CASE WHEN updated_at >= ? THEN 1 ELSE 0 END) as updatedLast30DaysCount, + SUM(CASE WHEN updated_at >= ? THEN 1 ELSE 0 END) as updatedLast7DaysCount, + SUM(CASE WHEN updated_at >= ? THEN 1 ELSE 0 END) as updatedLast24HrsCount', [ + Carbon::now()->subDays(30), + Carbon::now()->subDays(7), + Carbon::now()->subHours(24), + Carbon::now()->subDays(30), + Carbon::now()->subDays(7), + Carbon::now()->subHours(24) + ])->first(); + + $pageStats = [ + 'visitors' => [ + 'all' => visits('App\Models\User', $littlelink_name)->count(), + 'day' => visits('App\Models\User', $littlelink_name)->period('day')->count(), + 'week' => visits('App\Models\User', $littlelink_name)->period('week')->count(), + 'month' => visits('App\Models\User', $littlelink_name)->period('month')->count(), + 'year' => visits('App\Models\User', $littlelink_name)->period('year')->count(), + ], + 'os' => visits('App\Models\User', $littlelink_name)->operatingSystems(), + 'referers' => visits('App\Models\User', $littlelink_name)->refs(), + 'countries' => visits('App\Models\User', $littlelink_name)->countries(), + ]; + + } - $pageStats = [ - 'visitors' => [ - 'all' => visits('App\Models\User', $littlelink_name)->count(), - 'day' => visits('App\Models\User', $littlelink_name)->period('day')->count(), - 'week' => visits('App\Models\User', $littlelink_name)->period('week')->count(), - 'month' => visits('App\Models\User', $littlelink_name)->period('month')->count(), - 'year' => visits('App\Models\User', $littlelink_name)->period('year')->count(), - ], - 'os' => visits('App\Models\User', $littlelink_name)->operatingSystems(), - 'referers' => visits('App\Models\User', $littlelink_name)->refs(), - 'countries' => visits('App\Models\User', $littlelink_name)->countries(), - ]; - - return view('panel/index', [ - 'lastMonthCount' => $lastMonthCount, - 'lastWeekCount' => $lastWeekCount, - 'last24HrsCount' => $last24HrsCount, - 'updatedLast30DaysCount' => $updatedLast30DaysCount, - 'updatedLast7DaysCount' => $updatedLast7DaysCount, - 'updatedLast24HrsCount' => $updatedLast24HrsCount, - 'toplinks' => $topLinks, - 'links' => $links, - 'clicks' => $clicks, - 'pageStats' => $pageStats, - 'littlelink_name' => $littlelink_name, - 'siteLinks' => $siteLinks, - 'siteClicks' => $siteClicks, - 'userNumber' => $userNumber + return view('studio/index', [ + 'links' => $userLinksData->links ?? null, + 'clicks' => $userLinksData->clicks ?? null, + 'userNumber' => $userCounts->userNumber ?? null, + 'siteLinks' => $siteLinksData->siteLinks ?? null, + 'siteClicks' => $siteLinksData->siteClicks ?? null, + 'lastMonthCount' => $userCounts->lastMonthCount ?? null, + 'lastWeekCount' => $userCounts->lastWeekCount ?? null, + 'last24HrsCount' => $userCounts->last24HrsCount ?? null, + 'updatedLast30DaysCount' => $userCounts->updatedLast30DaysCount ?? null, + 'updatedLast7DaysCount' => $userCounts->updatedLast7DaysCount ?? null, + 'updatedLast24HrsCount' => $userCounts->updatedLast24HrsCount ?? null, + 'toplinks' => $topLinks ?? [], + 'pageStats' => $pageStats ?? null, ]); } diff --git a/resources/views/panel/index.blade.php b/resources/views/panel/index.blade.php index a7a9be9..a7bea9c 100755 --- a/resources/views/panel/index.blade.php +++ b/resources/views/panel/index.blade.php @@ -2,178 +2,52 @@ @section('content') -
-
- -
-
-
-
-
+
+
-

{{__('messages.Dashboard')}}

- -
-
- -
{{__('messages.Total Links:')}} {{ $links }}
- -
{{__('messages.Link Clicks:')}} {{ $clicks }}
-
- -
-
{{__('messages.Top Links:')}}
- - @php $i = 0; @endphp - +
+
+
+
+
-
-
    - @if($toplinks == "[]") -
    -
    -
    -

    {{__('messages.You haven’t added any links yet')}}

    -
    -
    -
    - @else - @foreach($toplinks as $link) - @php $linkName = str_replace('default ','',$link->name) @endphp - @php $i++; @endphp - - @if($link->name !== "phone" && $link->name !== 'heading' && $link->button_id !== 96) -
  1. -
    -
    {{ $link->title }}
    - {{ $link->link }} -
    - {{ $link->click_number }} - {{__('messages.clicks')}} -
  2. - @endif - @endforeach - @endif -
-
+

{{ __('messages.Dashboard') }}

-
- -
-
-
-
-
- -
-
-
-
-
- -@if(auth()->user()->role == 'admin' && !config('linkstack.single_user_mode')) - -
-
{{__('messages.Site statistics:')}}

-
- -
-

{{ $siteLinks }}

- {{__('messages.Total links')}} -
- -
-

{{ $siteClicks }}

- {{__('messages.Total clicks')}} -
- -
-

{{ $userNumber }}

- {{__('messages.Total users')}} -
- -
-
+
+
+ Loading... +
+
+
+
-
-
-
- -
-
-
-
-
+
- -
-
{{__('messages.Registrations:')}}

-
+ @push('sidebar-stylesheets') + + @endpush + @push('sidebar-scripts') + + @endpush + @endsection diff --git a/resources/views/studio/index.blade.php b/resources/views/studio/index.blade.php new file mode 100644 index 0000000..762e6e2 --- /dev/null +++ b/resources/views/studio/index.blade.php @@ -0,0 +1,186 @@ +
+ +
+
+
+
+
+ +

{{ __('messages.Dashboard') }}

+ +
+
+ +
{{ __('messages.Total Links:') }} {{ $links }}
+ +
{{ __('messages.Link Clicks:') }} {{ $clicks }}
+
+ +
+
{{ __('messages.Top Links:') }}
+ + @php $i = 0; @endphp + + +
+
    + @if ($toplinks == '[]') +
    +
    +
    +

    + {{ __('messages.You haven’t added any links yet') }}

    +
    +
    +
    + @else + @foreach ($toplinks as $link) + @php $linkName = str_replace('default ','',$link->name) @endphp + @php $i++; @endphp + + @if ($link->name !== 'phone' && $link->name !== 'heading' && $link->button_id !== 96) +
  1. +
    +
    {{ $link->title }}
    + {{ $link->link }} +
    + {{ $link->click_number }} + - {{ __('messages.clicks') }} +
  2. + @endif + @endforeach + @endif +
+
+ +
+ +
+
+
+
+
+ + @if (auth()->user()->role == 'admin' && !config('linkstack.single_user_mode')) +
+
+
+
+
+ + +
+
{{ __('messages.Site statistics:') }}
+
+
+ +
+

+ {{ $siteLinks }}

+ {{ __('messages.Total links') }} +
+ +
+

{{ $siteClicks }} +

+ {{ __('messages.Total clicks') }} +
+ +
+

+ {{ $userNumber }}

+ {{ __('messages.Total users') }} +
+ +
+
+ +
+
+
+
+
+ +
+
+
+
+
+ + +
+
{{ __('messages.Registrations:') }}
+
+
+ +
+

{{ $lastMonthCount }}

+ {{ __('messages.Last 30 days') }} +
+ +
+

{{ $lastWeekCount }}

+ {{ __('messages.Last 7 days') }} +
+ +
+

{{ $last24HrsCount }}

+ {{ __('messages.Last 24 hours') }} +
+ +
+
+ +
+
+
+
+
+ +
+
+
+
+
+ + + +
+
{{ __('messages.Active users:') }}

+
+ +
+

{{ $updatedLast30DaysCount }} +

+ {{ __('messages.Last 30 days') }} +
+ +
+

{{ $updatedLast7DaysCount }} +

+ {{ __('messages.Last 7 days') }} +
+ +
+

{{ $updatedLast24HrsCount }} +

+ {{ __('messages.Last 24 hours') }} +
+ +
+
+
+
+
+
+
+ @endif + +
diff --git a/routes/web.php b/routes/web.php index c58d8b1..c47ade4 100755 --- a/routes/web.php +++ b/routes/web.php @@ -99,6 +99,7 @@ Route::group([ if(env('FORCE_ROUTE_HTTPS') == 'true'){URL::forceScheme('https');} if(isset($_COOKIE['LinkCount'])){if($_COOKIE['LinkCount'] == '20'){$LinkPage = 'showLinks20';}elseif($_COOKIE['LinkCount'] == '30'){$LinkPage = 'showLinks30';}elseif($_COOKIE['LinkCount'] == 'all'){$LinkPage = 'showLinksAll';} else {$LinkPage = 'showLinks';}} else {$LinkPage = 'showLinks';} //Shows correct link number Route::get('/dashboard', [AdminController::class, 'index'])->name('panelIndex'); +Route::get('/dashboard/site-stats', [AdminController::class, 'stats']); Route::get('/studio/index', function(){return redirect(url('dashboard'));}); Route::get('/studio/add-link', [UserController::class, 'AddUpdateLink'])->name('showButtons'); Route::post('/studio/edit-link', [UserController::class, 'saveLink'])->name('addLink');