From a11b9c910088f5e18d03eb67e4914919cbf4e59a Mon Sep 17 00:00:00 2001 From: husanjon Date: Tue, 28 Apr 2026 18:02:39 +0500 Subject: [PATCH] storage url o'zgartirildi --- .../Requests/Dashboard/Category/Request.php | 16 +++++++++---- .../Requests/Dashboard/Category/Update.php | 16 +++++++++---- app/Jobs/Dashboard/Category/Store.php | 2 +- .../components/Dashboard/Category/Store.vue | 1 + .../components/Dashboard/Category/Update.vue | 1 + resources/js/components/ProductEdit.vue | 24 ++++++++++++++----- 6 files changed, 45 insertions(+), 15 deletions(-) diff --git a/app/Http/Requests/Dashboard/Category/Request.php b/app/Http/Requests/Dashboard/Category/Request.php index 7a68998..b992964 100755 --- a/app/Http/Requests/Dashboard/Category/Request.php +++ b/app/Http/Requests/Dashboard/Category/Request.php @@ -8,6 +8,13 @@ use Illuminate\Support\Str; class Request extends FormRequest { + protected function prepareForValidation() + { + if (in_array($this->get('parent_id'), [0, '0', '', 'null', 'NULL'], true)) { + $this->merge(['parent_id' => null]); + } + } + /** * Get the validation rules that apply to the request. * @@ -22,7 +29,7 @@ class Request extends FormRequest 'name' => 'required|array', 'name.*' => 'required|string', 'image' => 'nullable|mimes:jpg,jpeg,png', - 'parent_id' => 'nullable', + 'parent_id' => 'nullable|integer|exists:categories,id', 'brands' => 'nullable|array', 'position' => 'nullable|numeric' ]; @@ -82,15 +89,16 @@ class Request extends FormRequest public function getParentId() { - if ($this->get('parent_id') > 0) - return $this->get('parent_id'); + if ((int) $this->get('parent_id') > 0) { + return (int) $this->get('parent_id'); + } return null; } public function getPosition(): int { - return $this->get('position'); + return (int) $this->get('position'); } public function getPopular(): bool diff --git a/app/Http/Requests/Dashboard/Category/Update.php b/app/Http/Requests/Dashboard/Category/Update.php index b885ff4..fb0f090 100755 --- a/app/Http/Requests/Dashboard/Category/Update.php +++ b/app/Http/Requests/Dashboard/Category/Update.php @@ -10,6 +10,13 @@ use Illuminate\Support\Str; class Update extends FormRequest { + protected function prepareForValidation() + { + if (in_array($this->get('parent_id'), [0, '0', '', 'null', 'NULL'], true)) { + $this->merge(['parent_id' => null]); + } + } + /** * Get the validation rules that apply to the request. * @@ -24,7 +31,7 @@ class Update extends FormRequest 'name' => 'required|array', 'name.*' => 'required|string', 'image' => 'nullable', - 'parent_id' => 'nullable', + 'parent_id' => 'nullable|integer|exists:categories,id', 'popular' => 'nullable', 'brands' => 'nullable|array', 'position' => 'nullable|numeric' @@ -80,15 +87,16 @@ class Update extends FormRequest public function getParentId() { - if ($this->get('parent_id') > 0) - return $this->get('parent_id'); + if ((int) $this->get('parent_id') > 0) { + return (int) $this->get('parent_id'); + } return null; } public function getPosition(): int { - return $this->get('position'); + return (int) $this->get('position'); } public function getPopular(): bool diff --git a/app/Jobs/Dashboard/Category/Store.php b/app/Jobs/Dashboard/Category/Store.php index b7b0e1f..2c4509a 100755 --- a/app/Jobs/Dashboard/Category/Store.php +++ b/app/Jobs/Dashboard/Category/Store.php @@ -43,7 +43,7 @@ class Store $category->save(); - $category->brands()->sync($request->brands, false); + $category->brands()->sync($request->brands ?? [], false); return $category; } diff --git a/resources/js/components/Dashboard/Category/Store.vue b/resources/js/components/Dashboard/Category/Store.vue index 300f4b9..1154bce 100755 --- a/resources/js/components/Dashboard/Category/Store.vue +++ b/resources/js/components/Dashboard/Category/Store.vue @@ -356,6 +356,7 @@ id="remove_cat" type="button" class="btn btn-secondary w-100" + @click="category.parent_id = 0" > {{ $t( diff --git a/resources/js/components/Dashboard/Category/Update.vue b/resources/js/components/Dashboard/Category/Update.vue index 5e88f94..946a5e2 100755 --- a/resources/js/components/Dashboard/Category/Update.vue +++ b/resources/js/components/Dashboard/Category/Update.vue @@ -359,6 +359,7 @@ id="remove_cat" type="button" class="btn btn-secondary w-100" + @click="category.parent_id = 0" > {{ $t( diff --git a/resources/js/components/ProductEdit.vue b/resources/js/components/ProductEdit.vue index da1fc65..b72d613 100755 --- a/resources/js/components/ProductEdit.vue +++ b/resources/js/components/ProductEdit.vue @@ -1176,11 +1176,16 @@ export default { this.category.three = {}; this.category.three_view = false; - if (this.category.first.parents.length > 0) { + if (!this.category.first || !this.category.first.id) { + this.products.category_id = null; + return; + } + + this.products.category_id = this.category.first.id; + this.getCharacteristics(this.category.first.id); + + if (this.category.first.parents && this.category.first.parents.length > 0) { this.category.two_view = true; - } else { - this.getCharacteristics(this.category.first.id); - this.products.category_id = this.category.first.id; } }, @@ -1188,14 +1193,21 @@ export default { this.category.three = {}; this.category.three_view = false; - if (this.category.two.parents.length > 0) { + if (!this.category.two || !this.category.two.id) { + return; + } + + this.products.category_id = this.category.two.id; + this.getCharacteristics(this.category.two.id); + + if (this.category.two.parents && this.category.two.parents.length > 0) { this.category.three_view = true; } }, DetectCategoryThree() { this.getCharacteristics(this.category.three.id); - this.product.category_id = this.category.three.id; + this.products.category_id = this.category.three.id; }, async getCharacteristics(id) {