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', 'نظر شما ثبت شد.');