/** * Creates a new GoodsType model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new GoodsType(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $GoodsTable = new \app\components\GoodsTable(); $GoodsTable->addGoodsTable($model->type); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $this->validate($request, ['type_name' => 'required|unique:goods_types|max:255']); $goodsType = new GoodsType(); $goodsType->type_name = Input::get('type_name'); if ($goodsType->save()) { return Redirect::to('admin/goods_types'); } else { return Redirect::back()->withInput()->withErrors('保存失败!'); } }