feat(tour): implement tour details page with comments system and dynamic sidebar
This commit is contained in:
@@ -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', 'ثبت نظر با خطا مواجه شد.');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user