feat: add descriptions for product table

This commit is contained in:
2025-09-18 14:12:02 +03:30
parent 04bbcb831a
commit e44d4064df
3 changed files with 38 additions and 0 deletions
@@ -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()) {
+4
View File
@@ -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()
{
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('products', function (Blueprint $table) {
$table->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');
});
});
}
};