Exemplo n.º 1
0
 public function store(Request $request, $transportingId)
 {
     $this->validate($request, ['name' => 'required', 'weight' => 'required']);
     $good = new Good();
     $good->name = $request->get('name');
     $good->weight = $request->get('weight');
     $good->transporting_id = $transportingId;
     $good->save();
     $transporting = Transporting::find($transportingId);
     $goods = $transporting->goods;
     return redirect(route('dashboard.good.index', ['transporting' => $transporting, 'goods' => $goods]));
 }
Exemplo n.º 2
0
 public function actionSave($id = 0)
 {
     $form = new \app\models\GoodForm();
     $post = Yii::$app->request->post();
     if ($form->load($post) && $form->validate()) {
         if ($id > 0) {
             $good_current = Good::findOne($id);
             if (!$good_current) {
                 throw new HttpException(404, 'Указанный Вами товар не найден');
             }
         } else {
             $good_current = new Good();
         }
         $category_id = intval($post['GoodForm']['category_id']);
         $good_current->name = trim(htmlspecialchars($post['GoodForm']['name']));
         $good_current->category_id = $category_id;
         $good_current->save();
         return $this->redirect(Url::To(['category/cat', 'id' => $category_id]));
     }
     return $this->redirect(Url::To(['good/' . ($id > 0 ? 'update' : 'add'), 'id' => $id]));
 }