コード例 #1
0
 public function postEditReservation()
 {
     if (Auth::check()) {
         $validation = \App\Models\ReservationEdit::validate(Input::all());
         if ($validation->passes()) {
             $save_res = \App\Models\Reservation::showReservation(Input::get('id'));
             DB::select(DB::raw('DELETE FROM rezervace WHERE cisrezervace = :some_variable'), array('some_variable' => Input::get('id')));
             /** Check if function does not return the same reservation **/
             foreach ($save_res as $value) {
                 $res = $value;
             }
             if (!\App\Models\Reservation::checkRoomCapacity((string) Input::get('room'), (string) Input::get('persons_number'))) {
                 DB::insert('INSERT INTO rezervace (cisrezervace, datum, datumdo, idzak, osob,cispokoje) VALUES (?, ?, ?, ?, ?, ?)', [$res->CisRezervace, $res->Datum, $res->DatumDo, $res->IDZak, $res->osob, $res->CisPokoje]);
                 return Redirect::route('editreservation')->withErrors(array('message' => 'Room does not have enough capacity. Please divide this reservation.'))->withInput()->with('previous', $res);
             }
             if (\App\Models\Reservation::isRoomAvailable(Input::get('date_from'), Input::get('date_to'), Input::get('room')) > 0) {
                 DB::insert('INSERT INTO rezervace (cisrezervace, datum, datumdo, idzak, osob,cispokoje) VALUES (?, ?, ?, ?, ?, ?)', [$res->CisRezervace, $res->Datum, $res->DatumDo, $res->IDZak, $res->osob, $res->CisPokoje]);
                 return Redirect::route('editreservation')->withErrors(array('message' => 'Room is occupied in this period!'))->withInput()->with('previous', $res);
             } else {
                 /** Here you have to edit database with input data, or in this case, insert new data **/
                 DB::insert('INSERT INTO rezervace (cisrezervace, datum, datumdo, idzak, osob, cispokoje) VALUES (?, ?, ?, ?, ?, ?)', [Input::get('id'), Input::get('date_from'), Input::get('date_to'), $res->IDZak, Input::get('persons_number'), Input::get('room')]);
                 return Redirect::route('home')->with('message', 'Your reservation was succesfully updated!');
             }
         } else {
             foreach (\App\Models\Reservation::showReservation(Input::get('id')) as $value) {
                 $my_reservation = $value;
             }
             return Redirect::route('editreservation')->withErrors($validation)->withInput()->with('previous', $my_reservation);
         }
     } else {
         return Redirect::route('home')->with('message', 'You are not logged in!');
     }
 }