diff --git a/app/Http/Controllers/admin/product/ProductCategoryController.php b/app/Http/Controllers/admin/product/ProductCategoryController.php index 88446c2..b2dcef2 100644 --- a/app/Http/Controllers/admin/product/ProductCategoryController.php +++ b/app/Http/Controllers/admin/product/ProductCategoryController.php @@ -76,6 +76,18 @@ class ProductCategoryController extends Controller return redirect()->route('products.group.trash')->with('success', 'Force Delete Group Success'); } + public function bulkDelete(Request $request) + { + $request->validate([ + 'ids' => 'required|array', + 'ids.*' => 'exists:product_categories,id' + ]); + + $this->productCategoryService->bulkDelete($request->ids); + + return response()->json(['message' => 'Selected product groups deleted successfully.']); + } + public function datatable(Request $request) { $query = $this->productCategoryRepository->filter( @@ -102,7 +114,13 @@ class ProductCategoryController extends Controller return view('administrator.pages.product.categories.datatable.status', ['row' => $d])->render(); } ) - ->rawColumns(['action', 'is_active']) + ->addColumn( + 'checkbox', + function ($d) { + return '
'; + } + ) + ->rawColumns(['action', 'is_active', 'checkbox']) ->make(true); } } \ No newline at end of file diff --git a/app/Http/Services/Admin/ProductCategory/ProductCategoryService.php b/app/Http/Services/Admin/ProductCategory/ProductCategoryService.php index ebbf67f..75105da 100644 --- a/app/Http/Services/Admin/ProductCategory/ProductCategoryService.php +++ b/app/Http/Services/Admin/ProductCategory/ProductCategoryService.php @@ -39,4 +39,9 @@ class ProductCategoryService implements ProductCategoryServiceInterface { return $this->repository->forceDelete($id); } + + public function bulkDelete(array $ids) + { + return $this->repository->bulkDelete($ids); + } } \ No newline at end of file diff --git a/app/Http/Services/Admin/ProductCategory/ProductCategoryServiceInterface.php b/app/Http/Services/Admin/ProductCategory/ProductCategoryServiceInterface.php index e513ab9..04690fa 100644 --- a/app/Http/Services/Admin/ProductCategory/ProductCategoryServiceInterface.php +++ b/app/Http/Services/Admin/ProductCategory/ProductCategoryServiceInterface.php @@ -10,4 +10,6 @@ interface ProductCategoryServiceInterface { public function restore(int $id); public function forceDelete(int $id); + + public function bulkDelete(array $ids); } \ No newline at end of file diff --git a/app/Repositories/Admin/ProductCategory/ProductCategoryRepository.php b/app/Repositories/Admin/ProductCategory/ProductCategoryRepository.php index e42b8d8..0e6722d 100644 --- a/app/Repositories/Admin/ProductCategory/ProductCategoryRepository.php +++ b/app/Repositories/Admin/ProductCategory/ProductCategoryRepository.php @@ -81,4 +81,9 @@ class ProductCategoryRepository extends BaseRepository implements ProductCategor } return false; } + + public function bulkDelete(array $ids) + { + return $this->model->whereIn('id', $ids)->delete(); + } } diff --git a/app/Repositories/Admin/ProductCategory/ProductCategoryRepositoryInterface.php b/app/Repositories/Admin/ProductCategory/ProductCategoryRepositoryInterface.php index c04275d..4bbdf9e 100644 --- a/app/Repositories/Admin/ProductCategory/ProductCategoryRepositoryInterface.php +++ b/app/Repositories/Admin/ProductCategory/ProductCategoryRepositoryInterface.php @@ -17,4 +17,6 @@ interface ProductCategoryRepositoryInterface extends BaseRepositoryInterface public function restore(int $id); public function forceDelete(int $id); + + public function bulkDelete(array $ids); } diff --git a/app/View/Components/DataTable.php b/app/View/Components/DataTable.php index 5be0e5f..3928ae8 100644 --- a/app/View/Components/DataTable.php +++ b/app/View/Components/DataTable.php @@ -11,15 +11,29 @@ class DataTable extends Component public string $id; public string $ajax; public array $columns; + public ?string $bulkDeleteUrl; public function __construct( string $id, string $ajax, - array $columns + array $columns, + ?string $bulkDeleteUrl = null ) { $this->id = $id; $this->ajax = $ajax; $this->columns = $columns; + $this->bulkDeleteUrl = $bulkDeleteUrl; + + if ($this->bulkDeleteUrl) { + array_unshift($this->columns, [ + 'key' => 'checkbox', + 'label' => '
', + 'orderable' => false, + 'searchable' => false, + 'className' => 'text-center align-middle', + 'width' => '30px' + ]); + } } /** diff --git a/resources/views/administrator/layout/partials/header.blade.php b/resources/views/administrator/layout/partials/header.blade.php index 9c95196..f8daf9d 100644 --- a/resources/views/administrator/layout/partials/header.blade.php +++ b/resources/views/administrator/layout/partials/header.blade.php @@ -16,18 +16,6 @@