fix:change user side bugs

This commit is contained in:
2026-08-22 11:17:00 +03:30
parent b76e979826
commit de1f8d5342
11 changed files with 225 additions and 45 deletions
@@ -8,37 +8,36 @@ use Illuminate\Support\Facades\Auth;
class FavoriteController extends Controller
{
public function toggle($type, $id)
public function toggle(string $type, int $id)
{
$query = Favorite::where('user_id', Auth::id());
$data = [
'user_id' => auth()->id(),
'flight_id' => null,
'tour_id' => null,
];
if ($type === 'flight') {
$query->where('flight_id', $id);
$data['flight_id'] = $id;
} elseif ($type === 'tour') {
$query->where('tour_id', $id);
$data['tour_id'] = $id;
} else {
abort(404);
}
$favorite = $query->first();
$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();
} else {
$data = [
'user_id' => Auth::id(),
];
if ($type === 'flight') {
$data['flight_id'] = $id;
} else {
$data['tour_id'] = $id;
}
Favorite::create($data);
return back()->with('success', 'از علاقه‌مندی‌ها حذف شد.');
}
return back();
Favorite::create($data);
return back()->with('success', 'به علاقه‌مندی‌ها اضافه شد.');
}
}