Skip to content
关注公众号,获取新课通知

修改商品


控制器 app/controller/admin/Goods.php

php
public function update(Request $request, $id)
   {	
   	$param = $request->param();
       return $request->Model->save($param);
   }

验证器 app/validate/Goods.php

php
protected $rule = [
    'id'=>'require|integer|>:0|isExist:Goods',
    'page'=>'require|integer|>:0',
    'status'=>'require|in:0,1',
    'title'	=>'require|NotEmpty',	 		
    'category_id' =>'require|integer|>=:0|isExist:Category,false',
    'cover'	=>'url',	       
    'unit' => 'require|NotEmpty',	        
    'stock'  => 'require|integer|>=:0',	   
    'min_oprice'  => 'require|float|>=:0',	 
    'min_stock'=>'require|integer|>=:0',	
    'ischeck'=>'require|in:0,1,2',	 	     	
    'stock_display'	=> 'require|in:0,1',	
    'express_id'=> 'require|integer|>:0|isExist:Express,false',
    'sku_type'	=> 'require|in:0,1',		
    'sku_value'=> 'requireIf:sku_type,0|array',	
    'goods_type_id'	=> 'require|integer|>:0|isExist:GoodsType,false',
    'content'=> 'require',			
    'discount'=> 'require|integer|between:0,100', 	
    'order'	=> 'require|integer|>:0',	
    'goods_skus_card_ids'=>'requireIf:sku_type,1|array|NotEmpty',
    'goods_attrs'=>'require|array|NotEmpty',
    
    'goodsSkus'=>'requireIf:sku_type,1|array',
    
    'comment_type'=>'in:good,bad,middle',
    
    'all'=>'in:desc,asc',
    'sale_count'=>'in:desc,asc',
    
    'ids'=>'require|array',
    
    'banners'=>'require|array',
];
 protected $scene = [
    'update'=>['id',"title","category_id","cover","desc", "unit","stock","min_stock","ischeck","status","stock_display","express_id","min_oprice"],
];

路由 router/admin.php

php
Route::post('goods/:id','admin.Goods/update');