/** * Create a Room for an Accommodation. * * @param RoomRequest $request * @param int $aid * @return Response */ public function store(RoomRequest $request, $aid) { try { $accommodation = Accommodation::find($aid); if (!$accommodation) { return response()->error(404, 'Accommodation Not Found'); } $cid = $accommodation->conference()->first()->getKey(); $user = $this->isConferenceManager($request, $cid); if (!$user) { return response()->error(403, 'You are not a manager of this conference!'); } $room = new Room($request->all()); $room->accommodation()->associate($accommodation); $room->save(); return response()->success(); } catch (Exception $e) { return response()->error(); } }
/** * Run the database seeds. * * @return void */ public function run() { // --------------------------------------------------------------------- // CONFERENCE 2 // --------------------------------------------------------------------- $conference = Conference::find(2); $accommodation = ['name' => 'Shangri-La Hotel Vancouver', 'address' => '1128 West Georgia Street', 'city' => 'Vancouver', 'country' => 'Canada']; $accommodation = new Accommodation($accommodation); $accommodation->conference()->associate($conference); $accommodation->save(); $room = ['room_no' => '100', 'guest_count' => 0, 'capacity' => 2]; $room = new Room($room); $room->accommodation()->associate($accommodation); $room->save(); $room = ['room_no' => '101', 'guest_count' => 0, 'capacity' => 3]; $room = new Room($room); $room->accommodation()->associate($accommodation); $room->save(); $room = ['room_no' => '102', 'guest_count' => 0, 'capacity' => 4]; $room = new Room($room); $room->accommodation()->associate($accommodation); $room->save(); $accommodation = ['name' => 'The Fairmont Hotel Vancouver', 'address' => '900 West Georgia Street', 'city' => 'Vancouver', 'country' => 'Canada']; $accommodation = new Accommodation($accommodation); $accommodation->conference()->associate($conference); $accommodation->save(); $room = ['room_no' => '200', 'guest_count' => 0, 'capacity' => 2]; $room = new Room($room); $room->accommodation()->associate($accommodation); $room->save(); $room = ['room_no' => '201', 'guest_count' => 0, 'capacity' => 3]; $room = new Room($room); $room->accommodation()->associate($accommodation); $room->save(); $room = ['room_no' => '202', 'guest_count' => 0, 'capacity' => 4]; $room = new Room($room); $room->accommodation()->associate($accommodation); $room->save(); }