From de1f8d53426a93f2c37526d6d11859d9c2ddf27b Mon Sep 17 00:00:00 2001 From: Bahar Date: Sat, 22 Aug 2026 11:17:00 +0330 Subject: [PATCH] fix:change user side bugs --- .../Account/EditProfileController.php | 28 +++++- .../Account/FavoriteController.php | 35 ++++--- .../Controllers/Admin/DashboardController.php | 94 +++++++++++++++++++ app/Http/Controllers/CommentController.php | 2 +- app/Http/Requests/EditProfilePostRequest.php | 8 ++ resources/views/admin/admins/edit.blade.php | 9 +- resources/views/admin/dashboard.blade.php | 65 +++++++++++++ resources/views/auth/login.blade.php | 9 -- resources/views/components/flight.blade.php | 2 - resources/views/layouts/navbar.blade.php | 10 +- routes/admin.php | 8 ++ 11 files changed, 225 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/Account/EditProfileController.php b/app/Http/Controllers/Account/EditProfileController.php index 2131aab..f2ce8d3 100644 --- a/app/Http/Controllers/Account/EditProfileController.php +++ b/app/Http/Controllers/Account/EditProfileController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Account; use App\Http\Controllers\Controller; use App\Http\Requests\EditProfilePostRequest; +use App\Models\File; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; @@ -17,8 +18,6 @@ class EditProfileController extends Controller } - - public function post(EditProfilePostRequest $request) { $user = auth()->user(); @@ -32,8 +31,30 @@ class EditProfileController extends Controller 'city_id', ]); - if ($request->filled('new_password')) { + if ($request->hasFile('image')) { + $image = $request->file('image'); + + $imageName = time() . rand(11111, 99999) . '.' . $image->extension(); + + $path = $image->storeAs( + 'user_images', + $imageName, + 'public' + ); + + $file = File::create([ + 'name' => $imageName, + 'size' => $image->getSize(), + 'original_name' => $image->getClientOriginalName(), + 'path' => $path, + 'extension' => $image->extension(), + ]); + + $inputs['image_id'] = $file->id; + } + + if ($request->filled('new_password')) { $inputs['password'] = Hash::make( $request->input('new_password') ); @@ -46,5 +67,4 @@ class EditProfileController extends Controller ->with('success', 'پروفایل با موفقیت بروزرسانی شد.'); } - } diff --git a/app/Http/Controllers/Account/FavoriteController.php b/app/Http/Controllers/Account/FavoriteController.php index 9bbe505..dc6d3c1 100644 --- a/app/Http/Controllers/Account/FavoriteController.php +++ b/app/Http/Controllers/Account/FavoriteController.php @@ -8,37 +8,36 @@ use Illuminate\Support\Facades\Auth; class FavoriteController extends Controller { - public function toggle($type, $id) + public function toggle(string $type, int $id) { - $query = Favorite::where('user_id', Auth::id()); + $data = [ + 'user_id' => auth()->id(), + 'flight_id' => null, + 'tour_id' => null, + ]; if ($type === 'flight') { - $query->where('flight_id', $id); + $data['flight_id'] = $id; } elseif ($type === 'tour') { - $query->where('tour_id', $id); + $data['tour_id'] = $id; } else { abort(404); } - $favorite = $query->first(); + $favorite = Favorite::query() + ->where('user_id', auth()->id()) + ->where('flight_id', $data['flight_id']) + ->where('tour_id', $data['tour_id']) + ->first(); if ($favorite) { $favorite->delete(); - } else { - $data = [ - 'user_id' => Auth::id(), - ]; - - if ($type === 'flight') { - $data['flight_id'] = $id; - } else { - $data['tour_id'] = $id; - } - - Favorite::create($data); + return back()->with('success', 'از علاقه‌مندی‌ها حذف شد.'); } - return back(); + Favorite::create($data); + + return back()->with('success', 'به علاقه‌مندی‌ها اضافه شد.'); } } diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index f9d1c81..e27a7fb 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -2,9 +2,11 @@ namespace App\Http\Controllers\Admin; +use App\Models\ActivityLog; use App\Models\Booking; use App\Models\Comment; use App\Models\Flight; +use App\Models\SiteVisit; use App\Models\Tour; use App\Models\User; use Illuminate\Routing\Controller; @@ -20,6 +22,95 @@ class DashboardController extends Controller $toursCount = Tour::count(); $commentsCount = Comment::count(); $usersCount = User::count(); + $viewsCount = SiteVisit::count(); + + $days = collect(range(9, 0))->map( + fn ($i) => Carbon::today()->subDays($i) + ); + + $visitsRaw = SiteVisit::selectRaw('DATE(created_at) as visit_date, COUNT(*) as total') + ->where('created_at', '>=', Carbon::today()->subDays(9)->startOfDay()) + ->groupBy('visit_date') + ->pluck('total', 'visit_date'); + + $visitsChartLabels = $days + ->map(fn ($d) => $d->locale('fa')->translatedFormat('d M')) + ->toArray(); + + $visitsChartData = $days + ->map(fn ($d) => (int) ($visitsRaw[$d->toDateString()] ?? 0)) + ->toArray(); + + $visitsChartOptions = [ + 'chart' => [ + 'type' => 'bar', + 'height' => 320, + 'toolbar' => ['show' => false], + 'fontFamily' => 'inherit', + ], + 'series' => [ + [ + 'name' => 'بازدید', + 'data' => $visitsChartData, + ], + ], + 'xaxis' => [ + 'categories' => $visitsChartLabels, + 'labels' => [ + 'style' => ['colors' => '#8c9097'], + ], + ], + 'yaxis' => [ + 'labels' => [ + 'style' => ['colors' => '#8c9097'], + ], + ], + 'plotOptions' => [ + 'bar' => [ + 'borderRadius' => 6, + 'columnWidth' => '45%', + 'distributed' => false, + ], + ], + 'fill' => [ + 'type' => 'gradient', + 'gradient' => [ + 'shade' => 'light', + 'type' => 'vertical', + 'shadeIntensity' => 0.4, + 'gradientToColors' => ['#8b5cf6'], + 'opacityFrom' => 1, + 'opacityTo' => 0.85, + 'stops' => [0, 100], + ], + ], + 'colors' => ['#5B93FF'], + 'dataLabels' => ['enabled' => false], + 'grid' => [ + 'strokeDashArray' => 4, + 'borderColor' => '#e8e8e8', + ], + 'tooltip' => [ + 'theme' => 'light', + ], + ]; + + $recentLogs = ActivityLog::query() + ->whereIn('model_type', [Tour::class, Flight::class]) + ->with('admin') + ->orderByDesc('created_at') + ->limit(10) + ->get() + ->map(function ($log) { + + $modelClass = $log->model_type; + $relatedModel = $modelClass::find($log->model_id); + + $log->model_title = $relatedModel->title ?? '(حذف شده)'; + $log->model_label = $log->model_type === Tour::class ? 'تور' : 'پرواز'; + + return $log; + }); return view('admin.dashboard', compact( 'bookingsCount', @@ -27,6 +118,9 @@ class DashboardController extends Controller 'toursCount', 'commentsCount', 'usersCount', + 'viewsCount', + 'visitsChartOptions', + 'recentLogs', )); } } diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index 72a9a17..12823de 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -37,7 +37,7 @@ class CommentController extends Controller 'guest_name' => auth()->guest() ? $data['guest_name'] : null, 'guest_email' => auth()->guest() ? $data['guest_email'] : null, 'comment' => $data['comment'], - 'status' => CommentStatus::PENDING, + 'status' => CommentStatus::APPROVED, ]); return back()->with('success', 'نظر شما ثبت شد.'); diff --git a/app/Http/Requests/EditProfilePostRequest.php b/app/Http/Requests/EditProfilePostRequest.php index ac83251..52f85bb 100644 --- a/app/Http/Requests/EditProfilePostRequest.php +++ b/app/Http/Requests/EditProfilePostRequest.php @@ -56,6 +56,14 @@ class EditProfilePostRequest extends FormRequest 'max:255', 'confirmed', ], + 'image' => [ + 'nullable', + 'image', + 'mimes:jpg,jpeg,png,webp', + 'max:2048', + ], + 'province_id' => ['nullable', 'string'], + 'city_id' => ['nullable', 'string'], ]; } } diff --git a/resources/views/admin/admins/edit.blade.php b/resources/views/admin/admins/edit.blade.php index f6f6629..01808c8 100644 --- a/resources/views/admin/admins/edit.blade.php +++ b/resources/views/admin/admins/edit.blade.php @@ -503,8 +503,6 @@
- - {{-- مشاهده --}}
@@ -528,7 +526,7 @@ class="form-check-label fw-medium" for="tour_view" > - مشاهده تورها + مشاهده تور
@@ -536,7 +534,6 @@
- {{-- ایجاد --}}
@@ -650,7 +647,6 @@
- {{-- مشاهده --}}
@@ -674,7 +670,7 @@ class="form-check-label fw-medium" for="flight_view" > - مشاهده پروازها + مشاهده پرواز
@@ -682,7 +678,6 @@
- {{-- ایجاد --}}
diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index dcfef03..83a410f 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -185,11 +185,76 @@
+ {{-- ⬇️ کارت جدید: تعداد بازدیدها ⬇️ --}} +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ تعداد بازدیدها +
+ +
+ {{ number_format($viewsCount) }} +
+ +
+ + کل بازدیدهای سایت + +
+ +
+ +
+ +
+ +
+ +
+ {{-- ⬆️ پایان کارت جدید ⬆️ --}} +
+ +
+ +
+ +
+ +
+
+ بازدید سایت (۱۰ روز اخیر) +
+
+ +
+
+
+ +
+ +
+ +
diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 4f5c1aa..e055941 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -60,15 +60,6 @@ @enderror
-
- - -
رمز عبور را فراموش کرده اید؟
diff --git a/resources/views/components/flight.blade.php b/resources/views/components/flight.blade.php index 20af497..1458733 100644 --- a/resources/views/components/flight.blade.php +++ b/resources/views/components/flight.blade.php @@ -156,8 +156,6 @@
- - {{-- Details --}}
diff --git a/resources/views/layouts/navbar.blade.php b/resources/views/layouts/navbar.blade.php index f7189ff..cf8a908 100644 --- a/resources/views/layouts/navbar.blade.php +++ b/resources/views/layouts/navbar.blade.php @@ -28,6 +28,11 @@ صفحه اصلی + +