public function saveReservation(Request $request) { $reservation = new Reservation(); if (!$request->input('locator_id') || !Locator::find($request->input('locator_id'))) { return response('Lokator nie został sprecyzowany', 500)->header('Content-Type', 'text/html; charset=utf-8'); } if (!$request->input('rooms')) { return response('Pokoje nie zostały sprecyzowane', 500)->header('Content-Type', 'text/html; charset=utf-8'); } foreach ($request->input('rooms') as $room) { if (!Room::find($room)) { return response('Pokój o numerze ' . $room . ' nie jest zdefiniowany w bazie danych.', 500)->header('Content-Type', 'text/html; charset=utf-8'); } } $reservation->locator_id = $request->input('locator_id'); $reservation->reservation_time = date('Y-m-d H:i:sZ', time()); $reservation->since = $request->input('since'); $reservation->till = $request->input('till'); $reservation->is_paid = $request->input('is_paid'); $reservation->dinners_count = $request->input('dinners_count'); $reservation->people_count = $request->input('people_count'); $reservation->save(); $reservation->rooms()->sync($request->input('rooms')); $reservation->save(); return response()->json($reservation); }
public function updateLocator(Request $request, $number) { $locator = Locator::find($number); if (!$locator) { return response('Lokator nie został odnaleziony.', 404)->header('Content-Type', 'text/html; charset=utf-8'); } if ($request->input('name')) { $locator->name = $request->input('name'); } if ($request->input('surname')) { $locator->surname = $request->input('surname'); } if ($request->input('email')) { $locator->email = $request->input('email'); } if ($request->input('phone')) { $locator->phone = $request->input('phone'); } $locator->save(); return response()->json($locator); }