fix:change user side bugs

This commit is contained in:
2026-08-22 11:17:00 +03:30
parent b76e979826
commit de1f8d5342
11 changed files with 225 additions and 45 deletions
@@ -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', 'پروفایل با موفقیت بروزرسانی شد.');
}
}
@@ -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', 'به علاقه‌مندی‌ها اضافه شد.');
}
}
@@ -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',
));
}
}
+1 -1
View File
@@ -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', 'نظر شما ثبت شد.');
@@ -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'],
];
}
}
+2 -7
View File
@@ -503,8 +503,6 @@
</h6>
<div class="row gy-3">
{{-- مشاهده --}}
<div class="col-xl-3 col-lg-4 col-md-6">
<div class="border rounded p-3 h-100">
@@ -528,7 +526,7 @@
class="form-check-label fw-medium"
for="tour_view"
>
مشاهده تورها
مشاهده تور
</label>
</div>
@@ -536,7 +534,6 @@
</div>
</div>
{{-- ایجاد --}}
<div class="col-xl-3 col-lg-4 col-md-6">
<div class="border rounded p-3 h-100">
@@ -650,7 +647,6 @@
<div class="row gy-3">
{{-- مشاهده --}}
<div class="col-xl-3 col-lg-4 col-md-6">
<div class="border rounded p-3 h-100">
@@ -674,7 +670,7 @@
class="form-check-label fw-medium"
for="flight_view"
>
مشاهده پروازها
مشاهده پرواز
</label>
</div>
@@ -682,7 +678,6 @@
</div>
</div>
{{-- ایجاد --}}
<div class="col-xl-3 col-lg-4 col-md-6">
<div class="border rounded p-3 h-100">
+65
View File
@@ -185,11 +185,76 @@
</div>
{{-- ⬇️ کارت جدید: تعداد بازدیدها ⬇️ --}}
<div class="col-xl-3 col-lg-6 col-md-6 col-sm-6">
<div class="card custom-card overflow-hidden">
<div class="card-body">
<div class="d-flex gap-3">
<div class="avatar avatar-md bg-warning svg-white">
<i class="fal fa-eye fs-24"></i>
</div>
<div>
<div class="flex-fill fw-medium fs-13 mb-1 text-dark">
تعداد بازدیدها
</div>
<div class="fs-22 fw-semibold mb-1 text-warning">
{{ number_format($viewsCount) }}
</div>
<div class="d-flex align-items-center fs-11">
<span class="text-default op-6">
کل بازدیدهای سایت
</span>
</div>
</div>
</div>
</div>
</div>
</div>
{{-- ⬆️ پایان کارت جدید ⬆️ --}}
</div>
</div>
</div>
<!-- End:: row-1 -->
<div class="row mt-4">
<div class="col-xl-12">
<div class="card custom-card">
<div class="card-header">
<div class="card-title">
بازدید سایت (۱۰ روز اخیر)
</div>
</div>
<div class="card-body">
<div
class="apex-chart"
data-options='@json($visitsChartOptions)'
></div>
</div>
</div>
</div>
</div>
</div>
-9
View File
@@ -60,15 +60,6 @@
@enderror
</div>
<div class="d-flex justify-content-between mb-3">
<div class="form-check">
<input class="form-check-input"
type="checkbox"
name="remember"
value id="remember">
<label class="form-check-label" for="remember">
مرا به یاد داشته باش
</label>
</div>
<a href="forgot-password.html" class="forgot-pass">رمز عبور را فراموش کرده اید؟</a>
</div>
<div class="d-flex align-items-center">
@@ -156,8 +156,6 @@
</div>
{{-- Details --}}
<div class="flight-text-btn">
<a href="{{ route('flights.show', $flight->id) }}">
+6 -4
View File
@@ -28,6 +28,11 @@
صفحه اصلی
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{route('account.profile')}}">
پروفایل من
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('flights.index') }}">
پرواز
@@ -38,11 +43,8 @@
تور
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{route('account.profile')}}">
پروفایل من
</a>
</li> <li class="nav-item">
<a class="nav-link" href="#">
تماس با ما
</a>
+8
View File
@@ -131,6 +131,10 @@ Route::prefix('admin')->name('admin.')->group(function () {
->name('destroy')
->middleware('admin.permission:flight_delete');
Route::get('logs', 'logs')
->name('logs')
->middleware('admin.permission:flight_view');
});
});
@@ -165,6 +169,10 @@ Route::prefix('admin')->name('admin.')->group(function () {
->name('destroy')
->middleware('admin.permission:tour_delete');
Route::get('logs', 'logs')
->name('logs')
->middleware('admin.permission:tour_view');
});
});