【发布时间】:2020-01-08 17:24:27
【问题描述】:
我正在尝试为网站制作大量删除功能,以同时删除产品列表。我通过excel插入数据。
控制器功能
public function destroy(Request $request)
{
ini_set('max_execution_time', 300);
$products = $request->all();
try {
DB::beginTransaction();
foreach ($products as $product) {
$dbProduct = $this->getProduct($product['SKU']);
Log::error($dbProduct);
$dbProduct->delete();
}
DB::commit();
} catch (Exception $e) {
DB::rollBack();
throw new HttpException(500, 'Sucedio un error eliminando la información favor intentar de nuevo');
}
}
private function getProduct($sku)
{
$product = Product::where('sku', $sku)->first();
return $product;
}
我不确定如何在 vue 部分执行 @click 方法,现在我有这个,但这是用于在其他页面上上传,不知道要更改什么以使其删除。它正在接收已分成 50 个一组的数组,即(数据,索引)。
sendData(data, index) {
this.loading = true;
this.error = {};
this.$http.post(this.baseUrl, data, this.params).then(
() => {
this.successAction();
this.statuses[index] = 1;
this.errorDis = false;
},
res => {
this.showErrors(res);
this.statuses[index] = 2;
this.errorDis = true;
}
);
}
目前我获得了成功状态,但它没有删除产品
【问题讨论】: