error('商品不存在!'); } // if(!empty($tags)){ // $tagsArr = []; // if(!empty($tags)){ // foreach($tags as $kt => $tag){ // if(empty($tag)){ // unset($tags[$kt]); // continue; // } // $tagsArr[] = $tag; // } // }; // $goods->tags = json_encode($tagsArr); // } if(!empty($spec)){ $goods->spec = $spec; $edit = true; } if($edit && $goods->save()){ return $this->error('修改成功!'); } return $this->error('未做任何修改或者修改失败!'); } /** * Build a form here. */ public function form() { $id = $this->getKey(); $goods = GoodsModel::select('name','tags','spec')->find($id); $goodName = empty($goods->name)?'':$goods->name; // $tags = empty($goods->tags)?[]:$goods->tags; $spec = empty($goods->spec)?[]:$goods->spec; $this->hidden('goods_id')->value($id); $this->display('name','商品名称')->value($goodName); // $this->tags('tags','标签')->options(['新品','热销','新鲜'])->value($tags); $this->table('spec', function (NestedForm $table) { $table->text('spec_key')->required()->help('如:净含量:500克,保质期:120天,包装:12个/盒等'); $table->text('spec_value')->required(); })->value($spec); } /** * The data of the form. * * @return array */ public function default() { return []; } }