diff --git a/app/Http/Controllers/admin/product/ProductCategoryController.php b/app/Http/Controllers/admin/product/ProductCategoryController.php index a75f01a..b0bf0aa 100644 --- a/app/Http/Controllers/admin/product/ProductCategoryController.php +++ b/app/Http/Controllers/admin/product/ProductCategoryController.php @@ -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')); } diff --git a/resources/views/administrator/pages/product/categories/create.blade.php b/resources/views/administrator/pages/product/categories/create.blade.php index cf6e79f..cf57a1b 100644 --- a/resources/views/administrator/pages/product/categories/create.blade.php +++ b/resources/views/administrator/pages/product/categories/create.blade.php @@ -11,7 +11,7 @@ ['label' => 'Product'], ['label' => 'Product / Services', 'url' => route('products.index')], ['label' => 'Product Categories', 'url' => route('products.group.index')], - ['label' => 'Add Product Group', 'active' => true], + ['label' => 'Create Category', 'active' => true], ]; @endphp @@ -39,51 +39,53 @@ @csrf
-
+
Basic Information
- - Category Name * + + @error('name') +
{{ $message }}
+ @enderror
+
+
-
- - -
- -
- - -
+
+
+
Parent Category
+
+
+ @include('administrator.pages.product.categories.partials.category-tree', [ + 'categories' => $categories, + 'selected' => old('parent_id'), + 'name' => 'parent_id', + ]) + @error('parent_id') +
{{ $message }}
+ @enderror
-
+
-
Classification
+
Settings
- + + + + @error('sort_order') +
{{ $message }}
+ @enderror +
-
- - Back - Create - Category - + + Back + Create + Category + @endsection @@ -113,11 +119,7 @@ @foreach (config('assets.datatable.js') as $datatable) @endforeach - -@endpush \ No newline at end of file +@endpush +@push('custom-scripts') + @include('administrator.pages.product.categories.partials.category-tree-scripts') +@endpush diff --git a/resources/views/administrator/pages/product/categories/edit.blade.php b/resources/views/administrator/pages/product/categories/edit.blade.php index 48ed5d6..3bd0320 100644 --- a/resources/views/administrator/pages/product/categories/edit.blade.php +++ b/resources/views/administrator/pages/product/categories/edit.blade.php @@ -16,104 +16,111 @@ @endphp @endsection - @section('tab') - @php - $tabs = [ - [ - 'label' => 'Product', - 'route' => 'products.index', - 'icon' => 'server', - ], - [ - 'label' => 'Product Group', - 'route' => 'products.group.index', - 'icon' => 'server', - ], - ]; - @endphp - - @endsection - - @section('content') -
- @csrf - @method('PUT') -
-
-
-
-
Basic Information
-
-
-
- - -
+@section('tab') + @php + $tabs = [ + [ + 'label' => 'Product', + 'route' => 'products.index', + 'icon' => 'server', + ], + [ + 'label' => 'Product Group', + 'route' => 'products.group.index', + 'icon' => 'server', + ], + ]; + @endphp + +@endsection -
- - -
- -
- - -
+@section('content') + + @csrf + @method('PUT') +
+
+
+
+
Basic Information
+
+
+
+ + + @error('name') +
{{ $message }}
+ @enderror
-
-
-
-
Classification
-
-
-
- - -
- -
- - -
-
-
+
+
+
Parent Category
+
+
+ @include('administrator.pages.product.categories.partials.category-tree', [ + 'categories' => $categories, + 'selected' => old('parent_id', $category->parent_id), + 'name' => 'parent_id', + 'exclude' => $category->id, + ]) + @error('parent_id') +
{{ $message }}
+ @enderror +
- - Cancel - Update Category - - - @endsection +
+
+
+
Settings
+
+
+
+ + +
+ +
+ + + @error('sort_order') +
{{ $message }}
+ @enderror +
+
+
+
+
+ + + Cancel + Update + Category + + +@endsection @push('plugin-scripts') @foreach (config('assets.datatable.js') as $datatable) @endforeach - +@endpush + +@push('custom-scripts') + @include('administrator.pages.product.categories.partials.category-tree-scripts') @endpush diff --git a/resources/views/administrator/pages/product/categories/partials/category-option.blade.php b/resources/views/administrator/pages/product/categories/partials/category-option.blade.php new file mode 100644 index 0000000..1fcce81 --- /dev/null +++ b/resources/views/administrator/pages/product/categories/partials/category-option.blade.php @@ -0,0 +1,12 @@ + +@if($category->children->isNotEmpty()) + @foreach($category->children as $child) + @include('administrator.pages.product.categories.partials.category-option', [ + 'category' => $child, + 'depth' => $depth + 1, + 'selected' => $selected, + ]) + @endforeach +@endif diff --git a/resources/views/administrator/pages/product/categories/partials/category-tree-item.blade.php b/resources/views/administrator/pages/product/categories/partials/category-tree-item.blade.php new file mode 100644 index 0000000..1141548 --- /dev/null +++ b/resources/views/administrator/pages/product/categories/partials/category-tree-item.blade.php @@ -0,0 +1,32 @@ +@if(!$exclude || $category->id != $exclude) + +
+ @if($category->children->isNotEmpty()) + + + + @else + + @endif + + {{ $category->name }} + @if(!$category->is_active) + Inactive + @endif +
+
+ @if($category->children->isNotEmpty()) + + @endif +@endif diff --git a/resources/views/administrator/pages/product/categories/partials/category-tree-scripts.blade.php b/resources/views/administrator/pages/product/categories/partials/category-tree-scripts.blade.php new file mode 100644 index 0000000..d99cebd --- /dev/null +++ b/resources/views/administrator/pages/product/categories/partials/category-tree-scripts.blade.php @@ -0,0 +1,131 @@ + + diff --git a/resources/views/administrator/pages/product/categories/partials/category-tree.blade.php b/resources/views/administrator/pages/product/categories/partials/category-tree.blade.php new file mode 100644 index 0000000..e604d43 --- /dev/null +++ b/resources/views/administrator/pages/product/categories/partials/category-tree.blade.php @@ -0,0 +1,45 @@ +@props(['categories', 'selected' => null, 'name' => 'parent_id', 'exclude' => null]) + +@php $treeId = str_replace(['[', ']', '.'], '-', $name); @endphp + + + +
+ + + + +
+
+ +
+ + Root (No Parent) +
+
+ @foreach($categories as $category) + @include('administrator.pages.product.categories.partials.category-tree-item', [ + 'category' => $category, + 'depth' => 0, + 'selected' => $selected, + 'exclude' => $exclude, + 'treeId' => $treeId, + ]) + @endforeach +
+
+
diff --git a/resources/views/administrator/pages/product/create.blade.php b/resources/views/administrator/pages/product/create.blade.php index b16bc51..2a47b4d 100644 --- a/resources/views/administrator/pages/product/create.blade.php +++ b/resources/views/administrator/pages/product/create.blade.php @@ -204,18 +204,20 @@
- + @include('administrator.pages.product.categories.partials.category-tree', [ + 'categories' => $group, + 'selected' => old('product_categories_id'), + 'name' => 'product_categories_id', + ]) + @error('product_categories_id') +
{{ $message }}
+ @enderror
{{-- Product Type --}}
@@ -406,3 +408,7 @@ }); @endpush + +@push('custom-scripts') + @include('administrator.pages.product.categories.partials.category-tree-scripts') +@endpush diff --git a/resources/views/administrator/pages/product/edit.blade.php b/resources/views/administrator/pages/product/edit.blade.php index 59686f4..af438a7 100644 --- a/resources/views/administrator/pages/product/edit.blade.php +++ b/resources/views/administrator/pages/product/edit.blade.php @@ -209,12 +209,14 @@ $breadcrumbItems = [ Thêm Group
- + @include('administrator.pages.product.categories.partials.category-tree', [ + 'categories' => $group, + 'selected' => old('product_categories_id', $product->product_categories_id), + 'name' => 'product_categories_id', + ]) + @error('product_categories_id') +
{{ $message }}
+ @enderror
{{-- Operating System (for VPS) --}} @@ -424,3 +426,7 @@ $breadcrumbItems = [ }); @endpush + +@push('custom-scripts') + @include('administrator.pages.product.categories.partials.category-tree-scripts') +@endpush \ No newline at end of file