public static function postAccomGuest() { if (Auth::check()) { $validation = \App\Models\Billing::validate(Input::all()); //dd($validation); if ($validation->passes()) { if (\App\Models\Reservation::isRoomAvailable(\Carbon\Carbon::now(), Input::get('date_to'), Input::get('room')) > 0) { return Redirect::route('accomguest')->withErrors(array('message' => 'Room is occupied in this period!'))->withInput(); } 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!'))->withInput(); } 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')]); } $pobyt_number_query = DB::select('SELECT MAX(cispobytu) AS maxx FROM pobyt'); $pobyt_number = $pobyt_number_query[0]->maxx + 1; DB::insert('INSERT INTO pobyt (cispobytu, datum, datumdo, idzak, osob, pokoj) VALUES (?, ?, ?, ?, ?, ?)', [$pobyt_number, \Carbon\Carbon::now(), Input::get('date_to'), Input::get('guest_id'), Input::get('persons_number'), Input::get('room')]); DB::insert('INSERT INTO obyvana (CisPobytu, IDZak) VALUES (?, ?)', [$pobyt_number, Input::get('guest_id')]); return Redirect::route('home')->with('message', 'Your accomodation was succesfull!'); } else { return Redirect::route('accomguest')->withErrors($validation)->withInput(); } } else { return Redirect::route('home')->with('message', 'You are not logged in!'); } }