public function postCreateReservation()
 {
     if (Auth::check()) {
         $validation = \App\Models\Reservation::validate(Input::all());
         if ($validation->passes()) {
             if (\App\Models\Reservation::isRoomAvailable(Input::get('date_from'), Input::get('date_to'), Input::get('room')) > 0) {
                 return Redirect::route('createreservation')->withErrors(array('message' => 'Room is occupied in this period!'))->withInput();
             }
             /** Get primary key of table rezervace and set value of new row (+1) **/
             $res_number_query = DB::select('SELECT MAX(cisrezervace) AS maxx FROM rezervace');
             if ($res_number_query[0]->maxx == 'NULL') {
                 $reservation_number = 1;
             } else {
                 $reservation_number = (int) $res_number_query[0]->maxx + 1;
             }
             //dd(Input::get('room'), Input::get('persons_number'));
             if (!\App\Models\Reservation::checkRoomCapacity(Input::get('room'), Input::get('persons_number'))) {
                 return Redirect::route('createreservation')->withErrors(array('message' => 'Room does not have enough capacity. Please divide this reservation.'))->withInput();
             }
             if (count(\App\Models\Reservation::checkIfExistsZakaznik(Input::get('user_id'))) == 0) {
                 /** Here, you have to check if user_id is valid ID number **/
                 DB::insert('INSERT INTO zakaznik (meno, rodnecislo, adresa, datnar, telcis, mail) VALUES (?, ?, ?, ?, ?, ?)', [Input::get('name'), Input::get('user_id'), Input::get('address'), Input::get('birth_date'), Input::get('telephone'), Input::get('mail')]);
             }
             DB::insert('INSERT INTO rezervace (cisrezervace, datum, datumdo, idzak, osob, cispokoje) VALUES (?, ?, ?, ?, ?, ?)', [$reservation_number, Input::get('date_from'), Input::get('date_to'), Input::get('user_id'), Input::get('persons_number'), Input::get('room')]);
             return Redirect::route('home')->with('message', 'Your reservation was succesfull!');
         } else {
             return Redirect::route('createreservation')->withErrors($validation)->withInput();
         }
     } else {
         return Redirect::route('home')->with('message', 'You are not logged in!');
     }
 }
Esempio n. 2
0
 public static function postAddGuest()
 {
     if (Auth::check()) {
         $validation = \App\Models\Guest::validate(Input::all());
         if ($validation->passes()) {
             if (count(\App\Models\Reservation::checkIfExistsZakaznik(Input::get('guest_id'))) == 0) {
                 /** Here, you have to check if user_id is valid ID number **/
                 DB::insert('INSERT INTO zakaznik (meno, rodnecislo, adresa, datnar, telcis, mail) VALUES (?, ?, ?, ?, ?, ?)', [Input::get('name'), Input::get('guest_id'), Input::get('address'), Input::get('birth_date'), Input::get('telephone'), Input::get('mail')]);
             }
             DB::insert('INSERT INTO obyvana (CisPobytu, IDZak) VALUES (?, ?)', [Input::get('id'), Input::get('guest_id')]);
             return Redirect::route('home')->with('message', 'Guest successfully added!');
         } else {
             return Redirect::route('addguest')->withErrors($validation)->withInput()->with('id', Input::get('id'));
         }
     } else {
         return Redirect::route('home')->with('message', 'You are not logged in!');
     }
 }