Goods.php 商品控制器 upload修改logo方法
public function update(Request $request, $id)
{
$input = input();
$rule = [
'goods_name|商品名称' => 'require',
'goods_price|商品价格' => 'require|float|>=:0',
'goods_number|商品数量' => 'require|integer|>=:0'
];
$msg = [
'goods_price.float' => '商品价格必须是大于0的数字',
'goods_number.integer' => '商品数量必须是大于0的整数'
];
$validate = new Validate($rule,$msg);
if(!$validate->check($input)){
return $this->success($validate->getError());
}
$upload = request()->file('upload');;
if(empty($upload)){
unset($input['goods_logo']);
}else{
$goods = \app\admin\model\Goods::find($id);
$input['goods_logo'] = $this->get_Upload();
}
if(isset($goods)){
unlink('.'.$goods->goods_logo);
}
$res = \app\admin\model\Goods::update($input,['id' => $id],true);
if($res){
return $this->success('修改成功!','index');
}
}
edit.html 视图页面
|