This commit is contained in:
pbao9
2026-02-07 17:50:36 +07:00
parent 2a6a5d2131
commit e9f2218030
10 changed files with 601 additions and 245 deletions
@@ -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 '<div class="form-check d-flex align-items-center justify-content-center"><input class="form-check-input dt-checkbox" type="checkbox" value="' . $d->id . '"></div>';
}
)
->rawColumns(['action', 'is_active', 'checkbox'])
->make(true);
}
}
@@ -39,4 +39,9 @@ class ProductCategoryService implements ProductCategoryServiceInterface
{
return $this->repository->forceDelete($id);
}
public function bulkDelete(array $ids)
{
return $this->repository->bulkDelete($ids);
}
}
@@ -10,4 +10,6 @@ interface ProductCategoryServiceInterface {
public function restore(int $id);
public function forceDelete(int $id);
public function bulkDelete(array $ids);
}
@@ -81,4 +81,9 @@ class ProductCategoryRepository extends BaseRepository implements ProductCategor
}
return false;
}
public function bulkDelete(array $ids)
{
return $this->model->whereIn('id', $ids)->delete();
}
}
@@ -17,4 +17,6 @@ interface ProductCategoryRepositoryInterface extends BaseRepositoryInterface
public function restore(int $id);
public function forceDelete(int $id);
public function bulkDelete(array $ids);
}
+15 -1
View File
@@ -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' => '<div class="form-check d-flex align-items-center justify-content-center"><input class="form-check-input" type="checkbox" id="dt-master-checkbox"></div>',
'orderable' => false,
'searchable' => false,
'className' => 'text-center align-middle',
'width' => '30px'
]);
}
}
/**