auth()->id(), 'flight_id' => null, 'tour_id' => null, ]; if ($type === 'flight') { $data['flight_id'] = $id; } elseif ($type === 'tour') { $data['tour_id'] = $id; } else { abort(404); } $favorite = Favorite::query() ->where('user_id', auth()->id()) ->where('flight_id', $data['flight_id']) ->where('tour_id', $data['tour_id']) ->first(); if ($favorite) { $favorite->delete(); return back()->with('success', 'از علاقه‌مندی‌ها حذف شد.'); } Favorite::create($data); return back()->with('success', 'به علاقه‌مندی‌ها اضافه شد.'); } }