feat(tour): implement tour details page with comments system and dynamic sidebar

This commit is contained in:
2026-08-18 16:14:14 +03:30
parent 83cca25dd8
commit c3d6bed0f1
8 changed files with 236 additions and 12 deletions
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App\Enums;
enum CommentStatus:int
{
case PENDING= 0;
case CONFIRMED= 1;
case REJECTED= 2;
public function label(): string
{
return match($this) {
self::PENDING => 'در انتظار',
self::CONFIRMED => 'تایید شده',
self::REJECTED => 'رد شده',
};
}
}
@@ -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'));
}
}
+36 -1
View File
@@ -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', 'ثبت نظر با خطا مواجه شد.');
}
}
}
@@ -0,0 +1,54 @@
<?php
namespace App\Http\Requests\Tour;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class TourCommentStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|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',
],
];
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
namespace App\Models;
use App\Enums\CommentStatus;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -46,7 +47,7 @@ class Comment extends Model
'tour_id' => 'int',
'flight_id' => 'int',
'parent_id' => 'int',
'status' => 'int'
'status' => CommentStatus::class
];
protected $fillable = [
+100
View File
@@ -0,0 +1,100 @@
@extends('account.layouts.app')
@section('account-content')
<div class="user-profile-wrapper">
@if (session('success'))
<div class="col-lg-12 mb-3">
<div class="alert alert-success">
{{ session('success') }}
</div>
</div>
@endif
@if (session('error'))
<div class="col-lg-12 mb-3">
<div class="alert alert-danger">
{{ session('error') }}
</div>
</div>
@endif
<div class="col-lg-12">
<div class="user-profile-card">
<div class="d-flex justify-content-between align-items-center mb-4">
<h4 class="user-profile-card-title mb-0">
<i class="far fa-comments"></i>
کامنت‌های من
</h4>
<span class="badge bg-primary">
{{ $comments->total() }} کامنت
</span>
</div>
@forelse($comments as $comment)
<div class="border rounded p-3 mb-3">
<div class="d-flex justify-content-between align-items-center mb-3">
@if($comment->tour)
<span class="badge bg-info px-3 py-2" style="font-size: 0.95rem;">
<i class="fas fa-umbrella-beach me-1"></i>
تور:
<a href="{{ route('tours.show', $comment->tour->id) }}"
class="text-white text-decoration-none fw-semibold">
{{ $comment->tour->title ?? ('تور شماره ' . $comment->tour->id) }}
</a>
</span>
@elseif($comment->flight)
<span class="badge bg-primary px-3 py-2" style="font-size: 0.95rem;">
<i class="fas fa-plane-departure me-1"></i>
پرواز:
<a href="{{ route('flights.show', $comment->flight->id) }}"
class="text-white text-decoration-none fw-semibold">
{{ $comment->flight->flight_number ?? ('پرواز شماره ' . $comment->flight->id) }}
</a>
</span>
@else
<span class="badge bg-secondary px-3 py-2" style="font-size: 0.95rem;">
عمومی
</span>
@endif
<span class="text-muted">
<i class="far fa-calendar-alt"></i>
{{ \Hekmatinasser\Verta\Verta::instance($comment->created_at)->format('Y/m/d - H:i') }}
</span>
@if(isset($comment->status))
@if($comment->status == \App\Enums\CommentStatus::PENDING)
<span class="badge bg-success">{{$comment->status->label()}}</span>
@elseif($comment->status == \App\Enums\CommentStatus::CONFIRMED)
<span class="badge bg-warning text-dark">{{$comment->status->label()}}</span>
@elseif($comment->status == \App\Enums\CommentStatus::REJECTED)
<span class="badge bg-danger">{{$comment->status->label()}}</span>
@endif
@endif
</div>
<p class="mb-0">
{{ $comment->content }}
</p>
</div>
@empty
<div class="text-center py-5">
<i class="far fa-comment-dots fa-3x text-muted mb-3"></i>
<h5>هنوز کامنتی ثبت نکرده‌اید.</h5>
<p class="text-muted mb-0">
بعد از ثبت نظر برای تورها یا پروازها، کامنت‌هایتان در این بخش نمایش داده می‌شوند.
</p>
</div>
@endforelse
@if ($comments->hasPages())
<div class="mt-4 d-flex justify-content-center">
{{ $comments->links() }}
</div>
@endif
</div>
</div>
</div>
@endsection
@@ -1,16 +1,16 @@
<div class="booking-sidebar listing-side-content">
<div class="booking-item">
<div class="listing-price">
<h4 class="listing-price-tag">تور</h4>
<div class="listing-price-amount">
<span>{{ number_format($tour->price) }} تومان</span>
</div>
</div>
@php
$departure = $tour->tourDepartures->first();
@endphp
<div class="listing-price">
<h4 class="listing-price-tag">تور</h4>
<div class="listing-price-amount">
<span>{{ $departure?->price ? number_format($departure->price) . ' تومان' : 'تماس بگیرید' }}</span>
</div>
</div>
<div class="search-form">
<form action="#">
@csrf
@@ -66,7 +66,6 @@
</div>
<div class="listing-side-share">
<a href="#"><i class="far fa-share-nodes"></i> اشتراک</a>
<span><i class="far fa-eye"></i> 250 مشاهده</span>
</div>
</div>
+2
View File
@@ -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 () {