58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
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\HasMany;
|
|
|
|
#[Fillable([
|
|
'propable_type',
|
|
'codigo',
|
|
'nombre',
|
|
'is_required',
|
|
'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
|
|
*/
|
|
public function scopeForModel(Builder $query, Model|string $model): void
|
|
{
|
|
$query->where('propable_type', is_string($model) ? $model : $model::class);
|
|
}
|
|
|
|
/**
|
|
* @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_id');
|
|
}
|
|
}
|