feat: implement hierarchical category selection with a tree view in product and category forms.

This commit is contained in:
pbao9
2026-02-13 14:25:37 +07:00
parent 3a10c3e2d7
commit 549e434627
9 changed files with 395 additions and 147 deletions
@@ -27,7 +27,10 @@ class ProductCategoryController extends Controller
public function create()
{
$categories = \App\Models\ProductCategories::all();
$categories = \App\Models\ProductCategories::with('children')
->whereNull('parent_id')
->orderBy('sort_order')
->get();
return view('administrator.pages.product.categories.create', compact('categories'));
}
@@ -43,7 +46,11 @@ class ProductCategoryController extends Controller
if (!$category) {
return redirect()->route('products.group.index')->with('error', 'Category not found');
}
$categories = \App\Models\ProductCategories::where('id', '!=', $id)->get();
$categories = \App\Models\ProductCategories::with('children')
->whereNull('parent_id')
->where('id', '!=', $id)
->orderBy('sort_order')
->get();
return view('administrator.pages.product.categories.edit', compact('category', 'categories'));
}