Refactor Prop model to use enum for data types; remove PropDataType model and update related requests and migrations
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Domains\Prop\Models;
|
||||
|
||||
use App\Domains\Prop\Support\PropDataType;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable([
|
||||
@@ -14,12 +14,23 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
'codigo',
|
||||
'nombre',
|
||||
'is_required',
|
||||
'data_type_id',
|
||||
'data_type',
|
||||
])]
|
||||
class Prop extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_required' => 'boolean',
|
||||
'data_type' => PropDataType::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
*/
|
||||
@@ -28,14 +39,6 @@ class Prop extends Model
|
||||
$query->where('propable_type', is_string($model) ? $model : $model::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<PropDataType, $this>
|
||||
*/
|
||||
public function dataType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PropDataType::class, 'data_type_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<PropOption, $this>
|
||||
*/
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user