From 18586719a41594bc10f5cce68877e591e2ceb77f Mon Sep 17 00:00:00 2001 From: Julian Prieber <60265788+JulianPrieber@users.noreply.github.com> Date: Thu, 2 Nov 2023 22:14:25 +0100 Subject: [PATCH] Updated users route --- app/Http/Controllers/AdminController.php | 52 ++---------------------- routes/web.php | 4 +- 2 files changed, 5 insertions(+), 51 deletions(-) diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 310e18d..83d4796 100755 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -72,58 +72,12 @@ class AdminController extends Controller 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, 'links' => $links, 'clicks' => $clicks, 'siteLinks' => $siteLinks, 'siteClicks' => $siteClicks, 'userNumber' => $userNumber]); } -// Get users by type -public function users(Request $request) +// Users page +public function users() { - // Query to get the admin user with non-null 'auth_as' value - $adminUser = User::whereNotNull('auth_as')->where('role', 'admin')->first(); - - $usersType = $request->type; - - $usersQuery = User::select('id', 'name', 'email', 'littlelink_name', 'role', 'block', 'email_verified_at', 'created_at', 'updated_at'); - - switch ($usersType) { - case 'user': - $usersQuery->where('role', 'user'); - break; - case 'vip': - $usersQuery->where('role', 'vip'); - break; - case 'admin': - $usersQuery->where('role', 'admin'); - break; - } - - $users = $usersQuery->get(); - - // Rest of your code to calculate click counts and link counts for each user - - foreach ($users as $user) { - $user->clicks = Link::where('user_id', $user->id)->sum('click_number'); - $user->links = Link::where('user_id', $user->id)->select('link')->count(); - } - - $data['users'] = $users; - $data['adminUser'] = $adminUser; - - return view('panel/users', $data); + return view('panel/users'); } - //Search user by name - public function searchUser(Request $request) - { - $searchTerm = $request->search; - $data['users'] = User::where('name', 'like', "%{$searchTerm}%") - ->orWhere('email', 'like', "%{$searchTerm}%") - ->orWhere('littlelink_name', 'like', "%{$searchTerm}%") - // ->orWhere('role', 'like', "%{$searchTerm}%") - // ->orWhere('block', 'like', "%{$searchTerm}%") - // ->orWhere('email_verified_at', 'like', "%{$searchTerm}%") - ->select('id', 'email', 'name', 'littlelink_name', 'role', 'block', 'email_verified_at', 'created_at', 'updated_at') - ->get(); - return view('panel/users', $data); - } - // Send test mail public function SendTestMail(Request $request) { diff --git a/routes/web.php b/routes/web.php index 0a48953..66d267d 100755 --- a/routes/web.php +++ b/routes/web.php @@ -135,6 +135,7 @@ Route::get('/studio/delete-user/{id}', [UserController::class, 'deleteUser'])->n Route::post('/auth-as', [AdminController::class, 'authAs'])->name('authAs'); // Catch all redirects +Route::get('/admin/users/all', fn() => redirect(route('showUsers'))); Route::get('/studio', fn() => redirect(url('dashboard'))); Route::get('/studio/edit-link', fn() => redirect(url('dashboard'))); @@ -161,8 +162,7 @@ Route::group([ ], function () { if(env('FORCE_ROUTE_HTTPS') == 'true'){URL::forceScheme('https');} Route::get('/panel/index', function(){return redirect(url('dashboard'));}); - Route::get('/admin/users/{type}', [AdminController::class, 'users'])->name('showUsers'); - Route::post('/admin/users/{name?}', [AdminController::class, 'searchUser'])->name('searchUser'); + Route::get('/admin/users', [AdminController::class, 'users'])->name('showUsers'); Route::get('/admin/links/{id}', [AdminController::class, 'showLinksUser'])->name('showLinksUser'); Route::get('/admin/deleteLink/{id}', [AdminController::class, 'deleteLinkUser'])->name('deleteLinkUser'); Route::get('/admin/users/block/{block}/{id}', [AdminController::class, 'blockUser'])->name('blockUser');