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
@@ -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',
],
];
}
}