public function post_new() { $input = Input::get(); $rules = array('year_id' => 'required', 'user_id' => 'required'); $validation = Validator::make($input, $rules); if ($validation->passes()) { $bundle_id = Input::get('bundle'); if ($bundle_id == 'custom') { $yes = Input::get('yes'); if (count($yes) < 1) { return Redirect::to('rms/wellbeing/orders/new')->withErrors('You must select at least one night.'); } unset($input['yes']); $wellbeing_order = WellbeingOrder::create($input); if ($yes) { foreach (WellbeingNight::current_nights()->get() as $night) { if (array_key_exists($night->id, $yes)) { if (intval($yes[$night->id]) == 1) { $wellbeing_order->nights()->attach($night->id); } } } } } else { $bundle = WellbeingBundle::find($bundle_id); $order = WellbeingOrder::create($input); $order->bundles()->attach($bundle); } return Redirect::to('rms/wellbeing/orders/')->with('success', 'Successfully Created Order'); } else { return Redirect::to('rms/wellbeing/orders/new')->withErrors($validation)->withInput(); } }
public function get_night_add($bundle_id, $night_id) { $bundle = WellbeingBundle::find($bundle_id); $night = WellbeingNight::find($night_id); $bundle->nights()->attach($night); return Redirect::to('rms/wellbeing/bundles/manage/' . $bundle_id); }