public function postAdd() { $input = Input::all(); $rules = Config::get('validations.service_plan'); $rules['name'][] = 'unique:service_plans'; $v = Validator::make($input, $rules); if ($v->fails()) { return Redirect::back()->withInput()->withErrors($v); } try { if ($input['policy_type'] == 'PolicySchema') { $input['policy_id'] = $input['schema_id']; // unset($input['schema_id']); } DB::transaction(function () use($input) { $plan = new Plan($input); if (!$plan->save()) { throw new Exception("Failed to save service plan."); } if ($input['plan_type'] == 1) { //if limited $limit = $this->_makeLimit($input); //new PlanLimit( $input ); if (!$plan->limit()->save($limit)) { throw new Exception("Failed to save Service Plan."); } } }); $this->notifySuccess("Service Plan successfully created."); return Redirect::route(self::HOME); } catch (Exception $e) { $this->notifyError($e->getMessage()); return Redirect::route(self::HOME); } }