diff --git a/app/Http/Controllers/admin/product/ProductCategoryController.php b/app/Http/Controllers/admin/product/ProductCategoryController.php index b2dcef2..7a5fd30 100644 --- a/app/Http/Controllers/admin/product/ProductCategoryController.php +++ b/app/Http/Controllers/admin/product/ProductCategoryController.php @@ -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 '
'; } ) - ->rawColumns(['action', 'is_active', 'checkbox']) + ->rawColumns(['details_control', 'action', 'is_active', 'checkbox']) ->make(true); } } \ No newline at end of file diff --git a/app/Models/ProductCategories.php b/app/Models/ProductCategories.php index 35d90b9..cc66b02 100644 --- a/app/Models/ProductCategories.php +++ b/app/Models/ProductCategories.php @@ -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() diff --git a/app/Repositories/Admin/ProductCategory/ProductCategoryRepository.php b/app/Repositories/Admin/ProductCategory/ProductCategoryRepository.php index 0e6722d..c65fd4e 100644 --- a/app/Repositories/Admin/ProductCategory/ProductCategoryRepository.php +++ b/app/Repositories/Admin/ProductCategory/ProductCategoryRepository.php @@ -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); diff --git a/resources/views/administrator/pages/product/categories/datatable/details_control.blade.php b/resources/views/administrator/pages/product/categories/datatable/details_control.blade.php new file mode 100644 index 0000000..05a06df --- /dev/null +++ b/resources/views/administrator/pages/product/categories/datatable/details_control.blade.php @@ -0,0 +1,3 @@ +@if($row->children->count() > 0) + +@endif diff --git a/resources/views/administrator/pages/product/categories/index.blade.php b/resources/views/administrator/pages/product/categories/index.blade.php index cca3d4a..d100ed6 100644 --- a/resources/views/administrator/pages/product/categories/index.blade.php +++ b/resources/views/administrator/pages/product/categories/index.blade.php @@ -41,6 +41,7 @@ $tabs = [