public function updateMenuReservation() { $reservation = Reservation::find(Input::get('id')); if (!$reservation) { return Redirect::back()->withErrors('Could not find reservation.'); } //$reservation->menus()->detach(); //$reservation->items()->detach(); $date1 = new DateTime($reservation->reservation_start); $date2 = new DateTime($reservation->reservation_end); $diff = $date2->diff($date1)->format("%a"); $diff += 1; $date1 = date_format($date1, 'l, jS F Y'); $date2 = date_format($date2, 'l, jS F Y'); $id = Input::get('id'); $total_price = 0; $package_price = 0; $pricezs = 0; $qty = Input::get('quantity'); $model = Input::get('model'); $invid = Input::get('invId'); $pricey = Input::get('pricey'); foreach ($reservation->menu() as $value) { $total_price += $value->price; } foreach ($reservation->item as $value) { } for ($i = 0; $i < count($qty); $i++) { if ($qty[$i] > 0) { $reservation->items()->attach($invid[$i], ['qty' => $qty[$i]]); $pricezs = $pricezs + (int) $pricey[$i] * $qty[$i]; } } for ($index = 1; $index <= $diff; $index++) { if (count(Input::get('menu' . $index)) > 0) { foreach (Input::get('menu' . $index) as $menu) { $reservation->menus()->attach($menu, ['day' => $index]); $price = Menu::find($menu); $total_price += $price->price; } } if (count(Input::get('package' . $index)) > 0) { foreach (Input::get('package' . $index) as $package) { foreach (DB::table('menu_package')->where('package_id', '=', $package)->get() as $fuckage) { $reservation->menus()->attach($fuckage->menu_id, ['day' => $index, 'package' => $package]); } $price = Packages::find($package); $package_price += $price->price; } } } $reservation->net_total = $total_price * $reservation->pax + $package_price + $pricezs; if ($reservation->save()) { return Redirect::back()->with('flash_message', 'Reservation has been saved!'); } else { return Redirect::back()->withErrors('Could not update reservation'); } }