34 lines
733 B
PHP
34 lines
733 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',
|
|
'price',
|
|
'component_type_id',
|
|
'specifications',
|
|
'is_official',
|
|
'created_by_user_id',
|
|
];
|
|
|
|
protected $casts = [
|
|
'specifications' => 'array', // автоматически преобразует JSON в массив
|
|
];
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by_user_id');
|
|
}
|
|
|
|
public function componentType()
|
|
{
|
|
return $this->belongsTo(ComponentType::class, 'component_type_id');
|
|
}
|
|
} |