On this page
媒体设置
控制器 app/controller/admin/Goods.php
php
// 更新当前商品的轮播图
public function updateBanners(){
// 删除之前
$goods_id = request()->Model->id;
request()->Model->goodsBanner()->where([
'goods_id'=>$goods_id
])->delete();
$banners = request()->param('banners');
$data = array_map(function($item) use($goods_id){
return [
'url'=>$item,
'goods_id'=>$goods_id
];
},$banners);
$res = request()->Model->goodsBanner()->saveAll($data);
return showSuccess($res);
}
验证器 app/validate/admin/Goods.php
php
// 验证规则
protected $rule = [
// ...
'id'=>'require|integer|>:0|isExist:Goods',
'banners'=>'require|array',
// ...
];
protected $scene = [
// ...
'updateBanners'=>['id','banners'],
];
路由 router/admin.php
php
Route::post('goods/banners/:id','admin.Goods/updateBanners');