feat: add descriptions for product table
This commit is contained in:
@@ -31,6 +31,8 @@ public function store(Request $request, $packageName)
|
|||||||
'title' => 'string|required',
|
'title' => 'string|required',
|
||||||
'price' => 'integer|required',
|
'price' => 'integer|required',
|
||||||
'type' => ['integer', Rule::in(Product::TYPES)],
|
'type' => ['integer', Rule::in(Product::TYPES)],
|
||||||
|
'descriptions' => 'array|nullable',
|
||||||
|
'descriptions.*' => 'string|max:1000',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!$packageName = PackageName::with('products')->where('name', $packageName)->first()) {
|
if (!$packageName = PackageName::with('products')->where('name', $packageName)->first()) {
|
||||||
@@ -49,6 +51,8 @@ public function update(Request $request, $packageName, $productId)
|
|||||||
'title' => 'string|required',
|
'title' => 'string|required',
|
||||||
'price' => 'integer|required',
|
'price' => 'integer|required',
|
||||||
'type' => ['integer', Rule::in(Product::TYPES)],
|
'type' => ['integer', Rule::in(Product::TYPES)],
|
||||||
|
'descriptions' => 'array|nullable',
|
||||||
|
'descriptions.*' => 'string|max:1000'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!$packageName = PackageName::with('products')->where('name', $packageName)->first()) {
|
if (!$packageName = PackageName::with('products')->where('name', $packageName)->first()) {
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ public function users()
|
|||||||
{
|
{
|
||||||
return $this->belongsToMany(User::class, 'user_product')->withPivot(['expire_at', 'purchase_token', 'gateway'])->withTimestamps();
|
return $this->belongsToMany(User::class, 'user_product')->withPivot(['expire_at', 'purchase_token', 'gateway'])->withTimestamps();
|
||||||
}
|
}
|
||||||
|
protected $casts = [
|
||||||
|
'descriptions' => 'array',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
public function packageName()
|
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user