Add Prop and ModelPropValue models with relationships; create migration files for props, prop options, prop data types, and model prop values
This commit is contained in:
@@ -2,9 +2,29 @@
|
||||
|
||||
namespace App\Domains\Product\Models;
|
||||
|
||||
use App\Domains\Prop\Models\ModelPropValue;
|
||||
use App\Domains\Prop\Models\Prop;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
class Brand extends Model
|
||||
{
|
||||
// Placeholder model for the product domain structure.
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return MorphMany<Prop, $this>
|
||||
*/
|
||||
public function props(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Prop::class, 'propable');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphMany<ModelPropValue, $this>
|
||||
*/
|
||||
public function propValues(): MorphMany
|
||||
{
|
||||
return $this->morphMany(ModelPropValue::class, 'valuable');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,29 @@
|
||||
|
||||
namespace App\Domains\Product\Models;
|
||||
|
||||
use App\Domains\Prop\Models\ModelPropValue;
|
||||
use App\Domains\Prop\Models\Prop;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
// Placeholder model for the product domain structure.
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return MorphMany<Prop, $this>
|
||||
*/
|
||||
public function props(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Prop::class, 'propable');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphMany<ModelPropValue, $this>
|
||||
*/
|
||||
public function propValues(): MorphMany
|
||||
{
|
||||
return $this->morphMany(ModelPropValue::class, 'valuable');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace App\Domains\Product\Models;
|
||||
|
||||
use App\Domains\Prop\Models\ModelPropValue;
|
||||
use App\Domains\Prop\Models\Prop;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
#[Fillable([
|
||||
'tenant_codigo',
|
||||
@@ -37,4 +40,20 @@ class Product extends Model
|
||||
{
|
||||
return $this->belongsTo(Tenant::class, 'tenant_codigo', 'codigo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphMany<Prop, $this>
|
||||
*/
|
||||
public function props(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Prop::class, 'propable');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphMany<ModelPropValue, $this>
|
||||
*/
|
||||
public function propValues(): MorphMany
|
||||
{
|
||||
return $this->morphMany(ModelPropValue::class, 'valuable');
|
||||
}
|
||||
}
|
||||
|
||||
38
app/Domains/Prop/Models/ModelPropValue.php
Normal file
38
app/Domains/Prop/Models/ModelPropValue.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Prop\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
#[Fillable([
|
||||
'valuable_type',
|
||||
'valuable_id',
|
||||
'prop_codigo',
|
||||
'value',
|
||||
])]
|
||||
class ModelPropValue extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'model_prop_values';
|
||||
|
||||
/**
|
||||
* @return MorphTo<Model, $this>
|
||||
*/
|
||||
public function valuable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Prop, $this>
|
||||
*/
|
||||
public function prop(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Prop::class, 'prop_codigo', 'codigo');
|
||||
}
|
||||
}
|
||||
56
app/Domains/Prop/Models/Prop.php
Normal file
56
app/Domains/Prop/Models/Prop.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Prop\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
#[Fillable([
|
||||
'propable_type',
|
||||
'propable_id',
|
||||
'scope',
|
||||
'codigo',
|
||||
'nombre',
|
||||
'is_required',
|
||||
'data_type_id',
|
||||
])]
|
||||
class Prop extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return MorphTo<Model, $this>
|
||||
*/
|
||||
public function propable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<PropDataType, $this>
|
||||
*/
|
||||
public function dataType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PropDataType::class, 'data_type_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<PropOption, $this>
|
||||
*/
|
||||
public function options(): HasMany
|
||||
{
|
||||
return $this->hasMany(PropOption::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<ModelPropValue, $this>
|
||||
*/
|
||||
public function modelValues(): HasMany
|
||||
{
|
||||
return $this->hasMany(ModelPropValue::class, 'prop_codigo', 'codigo');
|
||||
}
|
||||
}
|
||||
25
app/Domains/Prop/Models/PropDataType.php
Normal file
25
app/Domains/Prop/Models/PropDataType.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Prop\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable([
|
||||
'name',
|
||||
'code',
|
||||
])]
|
||||
class PropDataType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return HasMany<Prop, $this>
|
||||
*/
|
||||
public function props(): HasMany
|
||||
{
|
||||
return $this->hasMany(Prop::class, 'data_type_id');
|
||||
}
|
||||
}
|
||||
27
app/Domains/Prop/Models/PropOption.php
Normal file
27
app/Domains/Prop/Models/PropOption.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Prop\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable([
|
||||
'prop_id',
|
||||
'value',
|
||||
'label',
|
||||
'sort_order',
|
||||
])]
|
||||
class PropOption extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Prop, $this>
|
||||
*/
|
||||
public function prop(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Prop::class);
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Domains\Tenant\Models;
|
||||
|
||||
use App\Domains\Prop\Models\ModelPropValue;
|
||||
use App\Domains\Prop\Models\Prop;
|
||||
use App\Domains\Product\Models\Product;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
#[Fillable([
|
||||
'codigo',
|
||||
@@ -35,4 +38,20 @@ class Tenant extends Model
|
||||
->withPivot('valor')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphMany<Prop, $this>
|
||||
*/
|
||||
public function props(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Prop::class, 'propable');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphMany<ModelPropValue, $this>
|
||||
*/
|
||||
public function propValues(): MorphMany
|
||||
{
|
||||
return $this->morphMany(ModelPropValue::class, 'valuable');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user