public function formSucceeded(Form $form, $values)
 {
     // pro odchytavani chyb
     $error = null;
     // ostatni akce
     $product = new Model\Product($this->database);
     $values['id_user'] = $this->id_user;
     $imgs = $values['img'];
     unset($values['img']);
     // add / edit
     if ($values['id'] == null) {
         // add
         $p = $product->add($values);
         $product_id = $p->id;
         $form->getPresenter()->flashMessage('Produkt byl úspěšně vytvořen.');
     } else {
         // edit
         $error = $product->update($values, $values['id']);
         $product_id = $values['id'];
         $form->getPresenter()->flashMessage('Produkt byl úspěšně upraven.');
     }
     if ($error == null) {
         // nahrani fotek k produktu
         if ($imgs != null) {
             $photo_manager = new Model\Photo($this->database);
             $photo_manager->uploadProductPhotos($imgs, $product_id);
         }
         // presmerovani
         $form->getPresenter()->redirect('Homepage:product', $product_id);
     } else {
         $form->addError($error);
     }
 }
Ejemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param ProductRequest $request
  * @param Product $product
  * @return mixed
  */
 public function update(ProductRequest $request, Product $product)
 {
     //dd($request->all());
     $product->update($request->all());
     if ($product) {
         Flash::success('修改成功!');
         return Redirect::to('/admin/product/' . $product->id . '/edit');
     } else {
         Flash::error('修改失败!');
         return Redirect::back()->withInput();
     }
 }