From c3d6bed0f152e0bfdfb314ca2df8e4f62bc1ca81 Mon Sep 17 00:00:00 2001 From: mina-esn Date: Tue, 18 Aug 2026 16:14:14 +0330 Subject: [PATCH] feat(tour): implement tour details page with comments system and dynamic sidebar --- app/Enums/CommentStatus.php | 19 ++++ .../Controllers/Account/ProfileController.php | 14 +++ app/Http/Controllers/TourController.php | 37 ++++++- .../Requests/Tour/TourCommentStoreRequest.php | 54 ++++++++++ app/Models/Comment.php | 7 +- resources/views/account/comments.blade.php | 100 ++++++++++++++++++ .../views/tours/partials/sidebar.blade.php | 15 ++- routes/web.php | 2 + 8 files changed, 236 insertions(+), 12 deletions(-) create mode 100644 app/Enums/CommentStatus.php create mode 100644 app/Http/Requests/Tour/TourCommentStoreRequest.php create mode 100644 resources/views/account/comments.blade.php diff --git a/app/Enums/CommentStatus.php b/app/Enums/CommentStatus.php new file mode 100644 index 0000000..f72c11c --- /dev/null +++ b/app/Enums/CommentStatus.php @@ -0,0 +1,19 @@ + 'در انتظار', + self::CONFIRMED => 'تایید شده', + self::REJECTED => 'رد شده', + }; + } +} diff --git a/app/Http/Controllers/Account/ProfileController.php b/app/Http/Controllers/Account/ProfileController.php index 57d412b..d043430 100644 --- a/app/Http/Controllers/Account/ProfileController.php +++ b/app/Http/Controllers/Account/ProfileController.php @@ -25,5 +25,19 @@ class ProfileController extends Controller return response()->json($cities); } + public function comments() + { + $comments = auth()->user() + ->comments() + ->with([ + 'tour', + 'flight' + ]) + ->orderByDesc('created_at') + ->paginate(10); + + return view('account.comments' , compact('comments')); + } + } diff --git a/app/Http/Controllers/TourController.php b/app/Http/Controllers/TourController.php index f0d0eac..5f05379 100644 --- a/app/Http/Controllers/TourController.php +++ b/app/Http/Controllers/TourController.php @@ -2,6 +2,9 @@ namespace App\Http\Controllers; +use App\Enums\CommentStatus; +use App\Http\Requests\Tour\TourCommentStoreRequest; +use App\Models\Comment; use App\Models\Tour; use Illuminate\Http\Request; @@ -28,8 +31,40 @@ class TourController extends Controller public function show(Tour $tour) { $title= 'جزئیات تور'; - $tour->load(['file', 'originCity', 'city', 'tourDepartures', 'comments.user']); + $tour->load([ + 'file', + 'originCity', + 'city', + 'tourDepartures', + 'comments' => function ($query) { + $query->latest(); + }, + 'comments.user' + ]); return view('tours.show', compact('title' , 'tour')); } + public function commentStore(TourCommentStoreRequest $request, Tour $tour) + { + + try { + Comment::create([ + 'tour_id' => $tour->id, + 'user_id' => auth()->id(), + 'parent_id' => $request->parent_id, + 'guest_name' => auth()->check() ? null : $request->guest_name, + 'guest_email' => auth()->check() ? null : $request->guest_email, + 'content' => $request->content, + 'status' => CommentStatus::PENDING, + ]); + + return back()->with('success', 'نظر شما با موفقیت ثبت شد.'); + } catch (\Exception $e) { + return back() + ->withInput() + ->with('error', 'ثبت نظر با خطا مواجه شد.'); + + } + } + } diff --git a/app/Http/Requests/Tour/TourCommentStoreRequest.php b/app/Http/Requests/Tour/TourCommentStoreRequest.php new file mode 100644 index 0000000..8e962dd --- /dev/null +++ b/app/Http/Requests/Tour/TourCommentStoreRequest.php @@ -0,0 +1,54 @@ +|string> + */ + public function rules(): array + { + $isGuest = ! auth()->check(); + + return [ + 'guest_name' => [ + $isGuest ? 'required' : 'nullable', + 'string', + 'max:255', + ], + + 'guest_email' => [ + $isGuest ? 'required' : 'nullable', + 'email', + 'max:255', + ], + + 'content' => [ + 'required', + 'string', + 'min:5', + 'max:2000', + ], + + 'parent_id' => [ + 'nullable', + 'integer', + 'exists:comments,id', + ], + ]; + } +} diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 0decada..3173917 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -6,13 +6,14 @@ namespace App\Models; +use App\Enums\CommentStatus; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Comment - * + * * @property int $id * @property int|null $user_id * @property int|null $admin_id @@ -26,7 +27,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property Carbon $created_at * @property Carbon $updated_at * @property string|null $deleted_at - * + * * @property Flight|null $flight * @property Tour|null $tour * @property User|null $user @@ -46,7 +47,7 @@ class Comment extends Model 'tour_id' => 'int', 'flight_id' => 'int', 'parent_id' => 'int', - 'status' => 'int' + 'status' => CommentStatus::class ]; protected $fillable = [ diff --git a/resources/views/account/comments.blade.php b/resources/views/account/comments.blade.php new file mode 100644 index 0000000..43a11a1 --- /dev/null +++ b/resources/views/account/comments.blade.php @@ -0,0 +1,100 @@ +@extends('account.layouts.app') + +@section('account-content') +
+ + @if (session('success')) +
+
+ {{ session('success') }} +
+
+ @endif + + @if (session('error')) +
+
+ {{ session('error') }} +
+
+ @endif + +
+ +
+ +
+@endsection diff --git a/resources/views/tours/partials/sidebar.blade.php b/resources/views/tours/partials/sidebar.blade.php index b6d1455..e76357f 100644 --- a/resources/views/tours/partials/sidebar.blade.php +++ b/resources/views/tours/partials/sidebar.blade.php @@ -1,16 +1,16 @@
-
-

تور

-
- {{ number_format($tour->price) }} تومان -
-
- @php $departure = $tour->tourDepartures->first(); @endphp +
+

تور

+
+ {{ $departure?->price ? number_format($departure->price) . ' تومان' : 'تماس بگیرید' }} +
+
+
@csrf @@ -66,7 +66,6 @@
- اشتراک 250 مشاهده
diff --git a/routes/web.php b/routes/web.php index 63fa070..627e187 100644 --- a/routes/web.php +++ b/routes/web.php @@ -34,7 +34,9 @@ Route::prefix('tours')->controller(TourController::class)->name('tours.')->group Route::prefix('account')->name('accounts.')->middleware('auth')->group(function () { Route::controller(ProfileController::class)->group(function () { Route::get('/profile', 'index')->name('profile'); + Route::get('/comments', 'comments')->name('comments'); Route::get('/get-cities/{province_id}', 'getCities')->name('get-cities'); + }); Route::prefix('edit-profile')->name('edit-profile.')->controller(EditProfileController::class)->group(function () {