diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index c2adcd0..f3dcf11 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -31,6 +31,8 @@ public function store(Request $request, $packageName) 'title' => 'string|required', 'price' => 'integer|required', 'type' => ['integer', Rule::in(Product::TYPES)], + 'descriptions' => 'array|nullable', + 'descriptions.*' => 'string|max:1000', ]); if (!$packageName = PackageName::with('products')->where('name', $packageName)->first()) { @@ -49,6 +51,8 @@ public function update(Request $request, $packageName, $productId) 'title' => 'string|required', 'price' => 'integer|required', 'type' => ['integer', Rule::in(Product::TYPES)], + 'descriptions' => 'array|nullable', + 'descriptions.*' => 'string|max:1000' ]); if (!$packageName = PackageName::with('products')->where('name', $packageName)->first()) { diff --git a/app/Models/Product.php b/app/Models/Product.php index 4453bdd..0289ede 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -24,6 +24,10 @@ public function users() { return $this->belongsToMany(User::class, 'user_product')->withPivot(['expire_at', 'purchase_token', 'gateway'])->withTimestamps(); } + protected $casts = [ + 'descriptions' => 'array', + ]; + public function packageName() { diff --git a/database/migrations/2025_09_18_135805_add_descriptions_to_products_table.php b/database/migrations/2025_09_18_135805_add_descriptions_to_products_table.php new file mode 100644 index 0000000..49084cb --- /dev/null +++ b/database/migrations/2025_09_18_135805_add_descriptions_to_products_table.php @@ -0,0 +1,30 @@ +json('descriptions')->nullable()->after('title'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('products', function (Blueprint $table) { + Schema::table('products', function (Blueprint $table) { + $table->dropColumn('descriptions'); + }); + }); + } +};