From 854324813ed2739db931f8e713b385f960e1db04 Mon Sep 17 00:00:00 2001 From: shahrzad011 Date: Thu, 20 Aug 2026 08:20:29 +0330 Subject: [PATCH] fix: update public tour functionality --- app/Http/Controllers/admin/TourController.php | 220 +++++++++-- resources/views/tours/index.blade.php | 78 +++- resources/views/tours/show.blade.php | 352 +++++++++++++++++- 3 files changed, 617 insertions(+), 33 deletions(-) diff --git a/app/Http/Controllers/admin/TourController.php b/app/Http/Controllers/admin/TourController.php index dce8cb3..d5330fd 100644 --- a/app/Http/Controllers/admin/TourController.php +++ b/app/Http/Controllers/admin/TourController.php @@ -4,9 +4,9 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Http\Requests\TourStoreRequest; +use App\Models\Flight; use App\Models\Tour; use App\Models\TravelType; -use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; @@ -14,18 +14,37 @@ use Illuminate\Support\Str; class TourController extends Controller { + /** + * لیست تورها + */ public function index() { - $tours = Tour::latest()->paginate(10); - return view('admin.tours.index', compact('tours')); + // همه تورها نمایش داده می‌شوند + // اگر فقط تورهای تایید شده را می‌خواهی: + // ->where('status', 2) + $tours = Tour::latest()->paginate(20); + + // آخرین پروازهای تایید شده + $flights = Flight::where('status', 2) + ->latest() + ->paginate(3); + + return view('admin.tours.index', compact('tours', 'flights')); } + /** + * فرم ایجاد تور + */ public function create() { $travelTypes = TravelType::all(); + return view('admin.tours.create', compact('travelTypes')); } + /** + * ذخیره تور جدید + */ public function store(TourStoreRequest $request) { DB::beginTransaction(); @@ -33,89 +52,238 @@ class TourController extends Controller try { $data = $request->validated(); - // ساخت slug اگر خالی بود + // ساخت slug در صورت خالی بودن if (empty($data['slug'])) { $data['slug'] = Str::slug($data['title']); } + /* + * وضعیت تور + * + * 1 = در انتظار + * 2 = تایید شده + * + * اگر می‌خواهی تور بلافاصله در لیست نمایش داده شود، + * مقدار 2 قرار می‌دهیم. + */ + $data['status'] = 2; + + // ایجاد تور $tour = Tour::create($data); + // آپلود تصویر if ($request->hasFile('image')) { - $image = $request->file('image'); - $newFileName = time() . '.tour-image' . rand(11111, 99999) . '.' . $image->extension(); - $path = $image->storeAs('tours', $newFileName, 'public'); - $tour->update(['image' => $path]); + $image = $request->file('image'); + + $newFileName = + time() + . '.tour-image' + . rand(11111, 99999) + . '.' + . $image->extension(); + + $path = $image->storeAs( + 'tours', + $newFileName, + 'public' + ); + + $tour->update([ + 'image' => $path + ]); } DB::commit(); - return redirect()->route('admin.tours.index')->with('success', 'تور با موفقیت ایجاد شد.'); + + return redirect() + ->route('admin.tours.index') + ->with('success', 'تور با موفقیت ایجاد شد.'); } catch (\Exception $exception) { - Log::error($exception); + DB::rollBack(); - return back()->withInput()->withErrors(['general' => 'خطایی در ثبت رخ داد.']); + + Log::error($exception); + + return back() + ->withInput() + ->withErrors([ + 'general' => 'خطایی در ثبت تور رخ داد.' + ]); } } + /** + * نمایش جزئیات تور + */ public function show(Tour $tour) { return view('admin.tours.show', compact('tour')); } + /** + * فرم ویرایش تور + */ public function edit(Tour $tour) { $travelTypes = TravelType::all(); - return view('admin.tours.edit', compact('tour', 'travelTypes')); + + return view( + 'admin.tours.edit', + compact('tour', 'travelTypes') + ); } - public function update(TourStoreRequest $request, Tour $tour) - { + /** + * بروزرسانی تور + */ + public function update( + TourStoreRequest $request, + Tour $tour + ) { DB::beginTransaction(); try { + $data = $request->validated(); + // ساخت slug if (empty($data['slug'])) { $data['slug'] = Str::slug($data['title']); } + /* + * اگر status از فرم ارسال نشده باشد، + * وضعیت فعلی تور حفظ شود. + */ + if (!isset($data['status'])) { + $data['status'] = $tour->status ?? 2; + } + + // اگر تصویر جدید آپلود شده if ($request->hasFile('image')) { - // حذف عکس قبلی از حافظه - if ($tour->image && Storage::disk('public')->exists($tour->image)) { + + // حذف تصویر قبلی + if ( + $tour->image && + Storage::disk('public')->exists($tour->image) + ) { Storage::disk('public')->delete($tour->image); } $image = $request->file('image'); - $newFileName = time() . '.tour-image' . rand(11111, 99999) . '.' . $image->extension(); - $path = $image->storeAs('tours', $newFileName, 'public'); + + $newFileName = + time() + . '.tour-image' + . rand(11111, 99999) + . '.' + . $image->extension(); + + $path = $image->storeAs( + 'tours', + $newFileName, + 'public' + ); $data['image'] = $path; } + // بروزرسانی $tour->update($data); DB::commit(); - return redirect()->route('admin.tours.index')->with('success', 'تور با موفقیت به‌روزرسانی شد.'); + + return redirect() + ->route('admin.tours.index') + ->with( + 'success', + 'تور با موفقیت به‌روزرسانی شد.' + ); } catch (\Exception $exception) { - Log::error($exception); + DB::rollBack(); - return back()->withInput()->withErrors(['general' => 'خطایی در به‌روزرسانی رخ داد.']); + + Log::error($exception); + + return back() + ->withInput() + ->withErrors([ + 'general' => + 'خطایی در به‌روزرسانی تور رخ داد.' + ]); } } + /** + * حذف تصویر تور + */ public function removeImage(Tour $tour) { - // حذف تصویر تکی (اختیاری — می‌توانی منطق دلخواه بگذاری) - return back()->with('success', 'عملیات حذف تصویر انجام شد.'); + try { + + if ( + $tour->image && + Storage::disk('public')->exists($tour->image) + ) { + Storage::disk('public')->delete($tour->image); + } + + $tour->update([ + 'image' => null + ]); + + return back()->with( + 'success', + 'تصویر تور با موفقیت حذف شد.' + ); + + } catch (\Exception $exception) { + + Log::error($exception); + + return back()->withErrors([ + 'general' => + 'حذف تصویر با خطا مواجه شد.' + ]); + } } + /** + * حذف تور + */ public function destroy(Tour $tour) { - $tour->delete(); + try { - return redirect()->route('admin.tours.index') - ->with('success', 'تور با موفقیت حذف شد.'); + // حذف تصویر + if ( + $tour->image && + Storage::disk('public')->exists($tour->image) + ) { + Storage::disk('public')->delete($tour->image); + } + + // حذف تور + $tour->delete(); + + return redirect() + ->route('admin.tours.index') + ->with( + 'success', + 'تور با موفقیت حذف شد.' + ); + + } catch (\Exception $exception) { + + Log::error($exception); + + return back()->withErrors([ + 'general' => + 'حذف تور با خطا مواجه شد.' + ]); + } } } diff --git a/resources/views/tours/index.blade.php b/resources/views/tours/index.blade.php index e7922aa..ac9c7ce 100644 --- a/resources/views/tours/index.blade.php +++ b/resources/views/tours/index.blade.php @@ -3,11 +3,65 @@ @section('title', 'لیست تورها') @section('content') + + {{-- استایل دکمه علاقهمندی (مناسب برای کارتها) --}} + +

تورهای ما

+
@forelse($tours as $tour) -
+ @php + $isFavTour = in_array($tour->id, $favoriteTourIds ?? []); + @endphp + +
+ + {{-- دکمه علاقهمندی --}} + @auth +
+ @csrf + + + + +
+ @else + + + + @endauth
@empty

تور فعالی یافت نشد.

@@ -15,4 +69,26 @@
{{ $tours->links() }} + @endsection + + +{{--@extends('layouts.app')--}} + +{{--@section('title', 'لیست تورها')--}} + +{{--@section('content')--}} +{{--

تورهای ما

--}} +{{--
--}} +{{-- @forelse($tours as $tour)--}} +{{--
--}} +{{-- --}} +{{--
--}} + +{{-- @empty--}} +{{--

تور فعالی یافت نشد.

--}} +{{-- @endforelse--}} +{{--
--}} + +{{-- {{ $tours->links() }}--}} +{{--@endsection--}} diff --git a/resources/views/tours/show.blade.php b/resources/views/tours/show.blade.php index 703645a..0d2cdc5 100644 --- a/resources/views/tours/show.blade.php +++ b/resources/views/tours/show.blade.php @@ -1,7 +1,31 @@ @extends('layouts.app') +@section('title', $tour->title) + @section('content') + +
@@ -37,6 +61,25 @@ {{ $tour->title }} + {{-- دکمه علاقهمندی --}} + @auth +
+ @csrf + + + + +
+ @else + + + افزودن به علاقهمندی + + @endauth + {{-- اطلاعات اصلی --}}
@@ -293,6 +336,303 @@ @endsection + + +{{--@extends('layouts.app')--}} + +{{--@section('content')--}} + +{{--
--}} + +{{--
--}} + +{{--
--}} + +{{-- --}}{{-- تصویر تور --}} +{{--
--}} + +{{-- @if($tour->image)--}} + +{{-- --}} + +{{-- @else--}} + +{{--
--}} +{{-- تصویر برای این تور ثبت نشده است--}} +{{--
--}} + +{{-- @endif--}} + +{{--
--}} + + +{{-- --}}{{-- محتوای تور --}} +{{--
--}} + +{{-- --}}{{-- عنوان --}} +{{--

--}} +{{-- {{ $tour->title }}--}} +{{--

--}} + + +{{-- --}}{{-- اطلاعات اصلی --}} +{{--
--}} + +{{-- --}}{{-- نوع سفر --}} +{{--
--}} + +{{-- --}} +{{-- نوع سفر--}} +{{-- --}} + +{{-- --}} +{{-- {{ $tour->travelType->title ?? 'نامشخص' }}--}} +{{-- --}} + +{{--
--}} + + +{{-- --}}{{-- تاریخ شروع --}} +{{--
--}} + +{{-- --}} +{{-- تاریخ حرکت--}} +{{-- --}} + +{{-- --}} +{{-- {{ $tour->start_date--}} +{{-- ? \Carbon\Carbon::parse($tour->start_date)->format('Y/m/d')--}} +{{-- : 'نامشخص'--}} +{{-- }}--}} +{{-- --}} + +{{--
--}} + + +{{-- --}}{{-- تاریخ پایان --}} +{{--
--}} + +{{-- --}} +{{-- تاریخ پایان--}} +{{-- --}} + +{{-- --}} +{{-- {{ $tour->end_date--}} +{{-- ? \Carbon\Carbon::parse($tour->end_date)->format('Y/m/d')--}} +{{-- : 'نامشخص'--}} +{{-- }}--}} +{{-- --}} + +{{--
--}} + + +{{-- --}}{{-- مدت سفر --}} +{{--
--}} + +{{-- --}} +{{-- مدت سفر--}} +{{-- --}} + +{{-- --}} +{{-- {{ $tour->duration ?? 'نامشخص' }}--}} +{{-- --}} + +{{--
--}} + + +{{-- --}}{{-- قیمت --}} +{{--
--}} + +{{-- --}} +{{-- قیمت--}} +{{-- --}} + +{{-- --}} +{{-- {{ number_format($tour->price) }}--}} +{{-- تومان--}} +{{-- --}} + +{{--
--}} + + +{{-- --}}{{-- ظرفیت --}} +{{--
--}} + +{{-- --}} +{{-- ظرفیت--}} +{{-- --}} + +{{-- --}} +{{-- {{ $tour->capacity ?? 'نامحدود' }}--}} +{{-- --}} + +{{--
--}} + + +{{-- --}}{{-- تعداد بازدید --}} +{{--
--}} + +{{-- --}} +{{-- تعداد بازدید--}} +{{-- --}} + +{{-- --}} +{{-- {{ number_format($tour->views_count) }}--}} +{{-- --}} + +{{--
--}} + +{{--
--}} + + +{{-- --}}{{-- توضیحات --}} +{{--
--}} + +{{--

--}} +{{-- توضیحات سفر--}} +{{--

--}} + +{{-- @if($tour->description)--}} + +{{--

--}} +{{-- {{ $tour->description }}--}} +{{--

--}} + +{{-- @else--}} + +{{--

--}} +{{-- توضیحی برای این تور ثبت نشده است.--}} +{{--

--}} + +{{-- @endif--}} + +{{--
--}} + + +{{-- --}}{{-- پروازهای تور --}} +{{-- @if($tour->flights && $tour->flights->count())--}} + +{{--
--}} + +{{--

--}} +{{-- پروازهای این تور--}} +{{--

--}} + +{{-- @foreach($tour->flights as $flight)--}} + +{{--
--}} + +{{--
--}} + +{{-- --}} +{{-- مبدأ--}} +{{-- --}} + +{{-- --}} +{{-- {{ $flight->origin ?? '-' }}--}} +{{-- --}} + +{{--
--}} + + +{{--
--}} + +{{-- --}} +{{-- مقصد--}} +{{-- --}} + +{{-- --}} +{{-- {{ $flight->destination ?? '-' }}--}} +{{-- --}} + +{{--
--}} + +{{--
--}} + +{{-- @endforeach--}} + +{{--
--}} + +{{-- @endif--}} + + +{{-- --}}{{-- تورهای مرتبط --}} +{{-- @if($relatedTours->count())--}} + +{{-- --}} + +{{-- @endif--}} + + +{{-- --}}{{-- دکمه بازگشت --}} +{{--
--}} + +{{-- --}} +{{-- بازگشت به لیست تورها--}} +{{-- --}} + +{{--
--}} + +{{--
--}} + +{{--
--}} + +{{--
--}} + +{{--
--}} + +{{--@endsection--}} + {{-- resources/views/tours/show.blade.php --}} {{--@extends('layouts.app')--}} @@ -301,7 +641,7 @@ {{--@section('content')--}} {{--
--}} -{{-- --}}{{-- اطلاعات تور --}} +{{-- --}}{{----}}{{-- اطلاعات تور --}} {{--
--}} {{--
--}} {{--

{{ $tour->name }}

--}} @@ -325,7 +665,7 @@ {{--
--}} {{-- --}} -{{-- --}}{{-- ===== فرم رزرو تور ===== --}} +{{-- --}}{{----}}{{-- ===== فرم رزرو تور ===== --}} {{-- @auth--}} {{--
--}} {{--
--}} @@ -351,7 +691,7 @@ {{--
--}} {{--
--}} {{-- @else--}} -{{-- --}}{{-- کاربر لاگین نیست => دکمه ورود به روت login --}} +{{-- --}}{{----}}{{-- کاربر لاگین نیست => دکمه ورود به روت login --}} {{--
--}} {{-- برای رزرو تور ابتدا وارد شوید.--}} {{--
--}} @@ -365,7 +705,7 @@ {{--@section('content')--}} {{--

{{ $tour->title }}

--}} -{{-- --}}{{----}}{{-- گالری تصاویر (اسلایدر) --}} +{{-- --}}{{----}}{{----}}{{----}}{{-- گالری تصاویر (اسلایدر) --}} {{--