feat: implement user favorites and fix toggle functionality

This commit is contained in:
2026-08-22 08:34:29 +03:30
parent b0bf4838ba
commit 44b18e4957
6 changed files with 180 additions and 110 deletions
+17 -7
View File
@@ -6,6 +6,7 @@ use App\Enums\CommentStatus;
use App\Enums\Flight\FlightStatus;
use App\Http\Requests\Flight\FlightCommentStoreRequest;
use App\Models\Comment;
use App\Models\Favorite;
use App\Models\Flight;
use Illuminate\Http\Request;
@@ -33,7 +34,16 @@ class FlightController extends Controller
{
$title = 'جزئیات پرواز';
$flight->increment('views_count');
return view('flights.show' , compact('title' , 'flight'));
$isFavorite = false;
if (auth()->check()) {
$isFavorite = Favorite::where('user_id', auth()->id())
->where('flight_id', $flight->id)
->exists();
}
return view('flights.show', compact('title', 'flight', 'isFavorite'));
}
public function commentStore(FlightCommentStoreRequest $request, Flight $flight)
@@ -41,13 +51,13 @@ class FlightController extends Controller
try {
Comment::create([
'flight_id' => $flight->id,
'user_id' => auth()->id(),
'parent_id' => $request->parent_id,
'guest_name' => auth()->check() ? null : $request->guest_name,
'flight_id' => $flight->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,
'content' => $request->content,
'status' => CommentStatus::PENDING,
]);
return back()->with('success', 'نظر شما با موفقیت ثبت شد.');