123
This commit is contained in:
@@ -2,9 +2,38 @@
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
15
app/Models/ComponentType.php
Normal file
15
app/Models/ComponentType.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ComponentType extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'code'];
|
||||
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
31
app/Models/PCBuild.php
Normal file
31
app/Models/PCBuild.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PcBuild extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'name',
|
||||
'description',
|
||||
'is_ai_generated',
|
||||
'ai_prompt',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_ai_generated' => 'boolean',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
// Связь с пользователем
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user