feat: add FeaturedGroup and FeaturedProduct models with migrations for database structure
This commit is contained in:
20
app/Domains/Product/Models/FeaturedGroup.php
Normal file
20
app/Domains/Product/Models/FeaturedGroup.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Product\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
class FeaturedGroup extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'tenant_codigo',
|
||||||
|
'group_name',
|
||||||
|
'product_layout',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function featuredProducts(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(FeaturedProduct::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/Domains/Product/Models/FeaturedProduct.php
Normal file
25
app/Domains/Product/Models/FeaturedProduct.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Product\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
class FeaturedProduct extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'featured_group_id',
|
||||||
|
'product_id',
|
||||||
|
'order',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function featuredGroup(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(FeaturedGroup::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function product(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Product::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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::create('featured_groups', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('tenant_codigo');
|
||||||
|
$table->string('group_name');
|
||||||
|
$table->enum('product_layout', ['row', 'column_with_image', 'column_with_cart']);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('featured_groups');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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::create('featured_products', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('featured_group_id')->constrained('featured_groups')->onDelete('cascade');
|
||||||
|
$table->unsignedBigInteger('product_id');
|
||||||
|
$table->integer('order')->default(0);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('featured_products');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user