public function postAdd() { $input = Input::all(); $rules = array("title" => "required|min:10|max:100", 'file' => 'image'); $validation = Validator::make($input, $rules); if ($validation->fails()) { return Redirect::to('admin/coupons/add')->withErrors($validation)->withInput(); } else { $coupon = new Coupon(); $coupon->title = Input::get('title'); $coupon->description = Input::get('description'); $coupon->restriction = Input::get('restriction'); $coupon->user_id = Auth::user()->id; $coupon->latitude = Input::get('latitude'); $coupon->longitude = Input::get('longitude'); $coupon->category_id = Input::get('category'); $coupon->save(); if (Input::hasFile('file')) { if (getimagesize(Input::file('file')->getRealPath())) { $data->image = Input::file('file')->getRealPath(); $data->flush(); } } return Redirect::to('admin/coupons')->with("message", "Cupón agregado!"); } }
/** * Creates a new Coupon model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->can('couponCreate')) { $model = new Coupon(); $model->lastModifyDatetime = date("Y-m-d H:i:s"); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } else { if (Yii::$app->user->isGuest) { Yii::$app->user->loginRequired(); } else { throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.')); } } }