feat: Implement nested product category display in admin datatable with expandable rows.

This commit is contained in:
pbao9
2026-02-11 17:30:20 +07:00
parent 556b2c02e6
commit 99b61bfb51
5 changed files with 108 additions and 15 deletions
@@ -91,14 +91,17 @@ class ProductCategoryController extends Controller
public function datatable(Request $request)
{
$query = $this->productCategoryRepository->filter(
$request->all(),
[],
array_merge($request->all(), ['parent_id' => null]),
['children'],
[],
['*'],
true
);
return DataTables::eloquent($query)
->addColumn('details_control', function ($d) {
return view('administrator.pages.product.categories.datatable.details_control', ['row' => $d])->render();
})
->addColumn(
'action',
function ($d) use ($request) {
@@ -120,7 +123,7 @@ class ProductCategoryController extends Controller
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'])
->rawColumns(['details_control', 'action', 'is_active', 'checkbox'])
->make(true);
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ class ProductCategories extends Model
public function children()
{
return $this->hasMany(ProductCategories::class, 'parent_id');
return $this->hasMany(ProductCategories::class, 'parent_id')->with('children');
}
public function products()
@@ -44,9 +44,9 @@ class ProductCategoryRepository extends BaseRepository implements ProductCategor
$query->onlyTrashed();
}
// if (!empty($data['vcenter_id'])) {
// $query->where('vcenter_id', $data['vcenter_id']);
// }
if (array_key_exists('parent_id', $data)) {
$query->where('parent_id', $data['parent_id']);
}
if (!empty($withCount)) {
$query->withCount($withCount);