/** * Creates a new Advert model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Advert(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { /*$file = $request->file('pic');*/ $uploader = new FileUpload(); $uploader = $uploader->multiple_uploadPic('adverts/'); $advert = new Advert(); $advert->author_id = Auth::user()->id; $advert->title = $request->title; $advert->description = $request->description; $advert->genre = $request->genre; $advert->year = $request->year; $advert->publishing_house = $request->publishing_house; $advert->save(); return redirect()->action('Insertions\\AdvertsController@index'); }
/** * creates an advert */ public function createAdvert() { $currency = Currency::find()->where(['date' => 0])->asArray()->one(); if ($this->validate()) { $advert = new Advert(); $advert->user_id = Yii::$app->user->identity->getId(); $advert->category_id = $this->category_id; $advert->subcategory_id = $this->subcategory_id; $advert->region_id = $this->region_id; $advert->city_id = $this->city_id; $advert->title = $this->title; $advert->text = $this->text; $advert->price = $this->price; $advert->currency = $this->currency; $advert->u_price = $this->price * $currency[$this->currency]; $advert->created_at = time(); $advert->updated_at = time(); $advert->views = 0; if ($advert->save()) { return $advert; } } return null; }
public function updateAdv() { if ($this->validate()) { $advert = new Advert(); $advert->category_id = $this->category_id; $advert->subcategory_id = $this->subcategory_id; $advert->region_id = $this->region_id; $advert->city_id = $this->city_id; $advert->title = $this->title; $advert->text = $this->text; $advert->updated_at = time(); if ($advert->save()) { return $advert; } } return null; }
/** * creates an advert */ public function createAdvert() { if ($this->validate()) { $advert = new Advert(); $advert->user_id = Yii::$app->user->identity->getId(); $advert->category_id = $this->category_id; $advert->subcategory_id = $this->subcategory_id; $advert->region_id = $this->region_id; $advert->city_id = $this->city_id; $advert->title = $this->title; $advert->text = $this->text; $advert->price = $this->price; $advert->created_at = time(); $advert->updated_at = time(); $advert->views = 0; if ($advert->save()) { return $advert; } } return null; }
/** * Store a newly created resource in storage. * POST /adverts * * @return Response */ public function store() { $data = Input::all(); //unset all empty control foreach ($data as $key => $value) { if ($value == "") { unset($data[$key]); } } $advert = new Advert(); if ($advert->validate($data)) { $advert->fill($data); $user = Auth::user(); if ($user->isBuyer()) { $advert->buyer_id = $user->buyer->id; } elseif ($user->isBroker()) { $advert->broker_id = $user->broker->id; } else { Auth::logout(); return Redirect::to('/'); } $advert->save(); Alert::success('Your advert has been created successfully. Keep an eye on your inbox for sellers contacting you', 'Congratulations'); return Redirect::to(Auth::user()->role->name . '/adverts')->withSuccess('<strong>Congratulations. Your advert has been created successfully. Keep an eye on your inbox for messages from sellers/brokers.</strong>'); } Input::flash(); return View::make(Auth::user()->role->name . '.adverts.create')->withErrors($advert->getValidator()); }