commentable_type === 'tour') { $modelClass = Tour::class; } else { $modelClass = Flight::class; } $guestName = null; if (!auth()->check()) { $guestName = $request->guest_name; } Comment::create([ 'user_id' => auth()->id(), 'guest_name' => $guestName, 'commentable_id' => $request->commentable_id, 'commentable_type' => $modelClass, 'body' => $request->body, ]); return back()->with('success', 'نظر شما با موفقیت ثبت شد.'); } public function index() { $comments = auth()->user()->comments()->with('commentable')->latest()->get(); return view('dashboard.comments', compact('comments')); } }