/**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  App\Reservation $reservation
  * @return Response
  */
 public function update(Request $request, Reservation $reservation)
 {
     $this->validate($request, ['name' => 'required', 'gender' => 'required', 'phone' => 'required|numeric', 'address' => 'required', 'check_in' => 'required|date|after:' . \Carbon\Carbon::today()->addDays(-1)->format('Y-m-d'), 'check_out' => 'required|date|after:' . $request->input('check_in')]);
     $input = $request->only('name', 'gender', 'phone', 'address');
     if (Auth::user()->role != 'user') {
         $guest = Guest::findOrFail($reservation->guest_id);
         $guest->fill($input)->save();
         $reservation_data = ['guest_id' => $guest->id, 'guest_type' => 'guest', 'check_in' => $request->input('check_in'), 'check_out' => $request->input('check_out')];
     } else {
         $user = User::findOrFail(Auth::user()->id);
         $user->fill($input)->save();
         $reservation_data = ['check_in' => $request->input('check_in'), 'check_out' => $request->input('check_out')];
     }
     $reservation->fill($reservation_data)->save();
     $roomTypes = $request->input('room_type_id');
     $roomReserved = $request->input('total_room_reserved');
     for ($i = 0; $i < count($roomTypes); $i++) {
         $reservation->roomTypes()->detach($roomTypes[$i]);
         $reservation->roomTypes()->attach($roomTypes[$i], ['total_room_reserved' => $roomReserved[$i]]);
     }
     return redirect('/reservation');
 }