public function store() { if (Input::has('noteCommType_id')) { $rules = ['noteCommType' => 'required']; } else { $rules = ['noteCommType' => 'required |unique:noteCommType']; } $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } else { if (Input::has('noteCommType_id')) { $id = Input::get('noteCommType_id'); $noteType = NoteCommTypeModel::find($id); } else { $noteType = new NoteCommTypeModel(); } $noteType->noteCommType = Input::get('noteCommType'); $noteType->save(); $alert['msg'] = 'Note comm type has been saved successfully'; $alert['type'] = 'success'; } return Redirect::route('admin.noteCommType')->with('alert', $alert); }