public function success(Request $request, Reservation $reservation) { //change reservation status to complete $payment_id = Session::get('paypal_payment_id'); $reservation->status = 1; $reservation->payment_id = $payment_id; $cruise = Cruise::find($reservation->cruise_id); $cabin = Cabin::find($reservation->cabin_id); //deduct cabin number in the cruise DB::table('cruises_cabins')->where('cruise_id', $reservation->cruise_id)->where('cabin_id', $reservation->cabin_id)->increment('cabin_booked'); $reservation->save(); Session::forget('paypal_payment_id'); $full = 0; foreach ($cruise->cabins as $cabin) { if ($cabin->pivot->cabin_number == $cabin->pivot->cabin_booked) { $full++; } } if ($full == Cabin::all()->count()) { $cruise->status = 1; $cruise->save(); } return view('user.reservation', ['cruise' => $cruise, 'cabin' => $cabin, 'amenities' => $reservation->amenities()->get(), 'reservation' => $reservation])->with('status', 'Payment succcess!'); }