39 lines
989 B
PHP
39 lines
989 B
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
use Illuminate\Database\Eloquent\Model;
|
||
|
||
class Component extends Model
|
||
{
|
||
use HasFactory;
|
||
|
||
protected $fillable = [
|
||
'name',
|
||
'component_type_id',
|
||
'price',
|
||
'specifications',
|
||
'is_official',
|
||
'created_by_user_id',
|
||
];
|
||
|
||
protected $casts = [
|
||
'specifications' => 'array', // Автоматически преобразует JSON в массив
|
||
'is_official' => 'boolean',
|
||
'created_at' => 'datetime',
|
||
'updated_at' => 'datetime',
|
||
];
|
||
|
||
// Связь с типом компонента
|
||
public function type()
|
||
{
|
||
return $this->belongsTo(ComponentType::class, 'component_type_id');
|
||
}
|
||
|
||
// Связь с пользователем (если добавил пользователь)
|
||
public function createdBy()
|
||
{
|
||
return $this->belongsTo(User::class, 'created_by_user_id');
|
||
}
|
||
} |