?资源路由
Route::group('goods',function (){
Route::resource('blog','Login');
})->middleware(\app\admin\middleware\Login::class);
控制器
//添加数据
public function save(){
try {
//接收数据
$data = $this->request->param();
//图片上传
$photo = $this->request->file('goods_logo');
$data['goods_logo'] = $photo;
//参数验证
validate(Save::class)->check($data);
//图片上传
$goods_logo = \think\facade\Filesystem::disk('public')->putFile( 'topic', $photo);
//入库
$goods = new \app\admin\model\Login();
$result = $goods->save([
'goods_name' => $data['goods_name'],
'goods_price' => $data['goods_price'],
'market_price' => $data['market_price'],
'cost_price' => $data['cost_price'],
'goods_number' => $data['goods_number'],
'frozen_number' => $data['frozen_number'],
'goods_logo' => $goods_logo,
]);
if ($result){
return success();
}else{
return fail(2001,"添加失败");
}
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return fail(2001,$e->getError());
}
}
用postMan进行测试? ?http://www.api.com/index.php/admin/goods/blog
?
|