+ {{ __('Create Product Group') }} +
++ {{ __('Edit Product Groups') }} +
++ {{ __('Products Group') }} +
+{{ __('Account code') }} | +{{ __('Name') }} | +{{ __('Action') }} | +
---|---|---|
{{ $productGroup->code }} | +{{ $productGroup->name }} | ++ Edit + + | +
diff --git a/app/Http/Controllers/ProductGroupController.php b/app/Http/Controllers/ProductGroupController.php new file mode 100644 index 0000000..93f3d41 --- /dev/null +++ b/app/Http/Controllers/ProductGroupController.php @@ -0,0 +1,59 @@ +validate([ + 'code' => 'required|unique:product_groups,code|regex:/^\d{3}$/', + 'name' => 'required|max:20|string|regex:/^[\w\d\s]*$/u' + ]); + + Models\ProductGroup::create($validatedData); + + return redirect()->route('product-groups.index')->with('success', 'Product group created successfully.'); + } + + public function edit(Models\ProductGroup $productGroup) + { + return view('productGroups.edit', compact('productGroup')); + } + + public function update(Request $request, Models\ProductGroup $productGroup) + { + // TODO validate request + $validatedData = $request->validate([ + 'code' => 'required|unique:product_groups,code,'.$productGroup->id.',|regex:/^\d{3}$/', + 'name' => 'required|max:20|string|regex:/^[\w\d\s]*$/u' + ]); + + $productGroup->update($validatedData); + + return redirect()->route('product-groups.index')->with('success', 'Product group updated successfully.'); + } + + public function destroy(Models\ProductGroup $productGroup) + { + $productGroup->delete(); + + return redirect()->route('product-groups.index')->with('success', 'Product group deleted successfully.'); + } + +} diff --git a/app/Models/ProductGroup.php b/app/Models/ProductGroup.php index 0f7ddf0..0b5543b 100644 --- a/app/Models/ProductGroup.php +++ b/app/Models/ProductGroup.php @@ -13,6 +13,8 @@ class ProductGroup extends Model 'sellId', ]; + public $timestamps = false; + // Define relationships with other models (e.g., Subject) public function buySubject() diff --git a/resources/views/components/app-layout.blade.php b/resources/views/components/app-layout.blade.php index 97e7417..398348f 100644 --- a/resources/views/components/app-layout.blade.php +++ b/resources/views/components/app-layout.blade.php @@ -8,7 +8,7 @@
{{ __('Account code') }} | +{{ __('Name') }} | +{{ __('Action') }} | +
---|---|---|
{{ $productGroup->code }} | +{{ $productGroup->name }} | ++ Edit + + | +