Skip to content

Commit fbef418

Browse files
committed
refactoring
1 parent 25a4407 commit fbef418

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

app/Http/Controllers/Admin/ProductController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,12 @@ public function deleteProductAttribute($productAttributeId)
153153
*/
154154
public function destroy(Product $product)
155155
{
156+
$deletedData = $this->productRepository->delete($product->id);
156157
$path = 'products/'.$product->image;
157158
if (Storage::disk('public')->exists($path)) {
158159
Storage::disk('public')->delete($path);
159-
}
160-
return $this->productRepository->delete($product->id);
160+
}
161+
return $deletedData;
161162
}
162163

163164
public function bulk_delete(Request $request){

app/Repositories/ProductRepository.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,17 @@ public function delete(int $id){
125125
public function bulk_delete($selected_data)
126126
{
127127
$this->flush($this->CACHE_KEY);
128+
DB::beginTransaction();
128129
foreach ($selected_data as $product) {
129130
$found = $this->findById($product['id']);
130131
$path = 'products/'.$found['image'];
132+
131133
if (Storage::disk('public')->exists($path)) {
132134
Storage::disk('public')->delete($path);
133135
}
134-
DB::beginTransaction();
135136
$found->delete();
136-
DB::commit();
137137
}
138+
DB::commit();
139+
// success
138140
}
139141
}

0 commit comments

Comments
 (0)