123 #1
@@ -2,9 +2,38 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Component extends 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,14 +13,16 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('components', function (Blueprint $table) {
|
Schema::create('components', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
|
$table->string('name'); // Например: "Intel Core i5-12400F"
|
||||||
|
$table->foreignId('component_type_id')->constrained()->onDelete('cascade');
|
||||||
|
$table->decimal('price', 10, 2);
|
||||||
|
$table->json('specifications')->nullable(); // Для хранения характеристик
|
||||||
|
$table->boolean('is_official')->default(true); // true = админ, false = пользователь
|
||||||
|
$table->foreignId('created_by_user_id')->nullable()->constrained('users')->onDelete('set null');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->text('name');
|
|
||||||
$table->text('type');
|
|
||||||
$table->text('brand');
|
|
||||||
$table->text('model');
|
|
||||||
$table->integer('price');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse the migrations.
|
* Reverse the migrations.
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('component_types', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name'); // Например: "Процессор", "Видеокарта"
|
||||||
|
$table->string('code')->unique(); // Уникальный код: cpu, gpu, ram и т.д.
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Заполняем таблицу начальными данными (seed)
|
||||||
|
DB::table('component_types')->insert([
|
||||||
|
['name' => 'Процессор', 'code' => 'cpu'],
|
||||||
|
['name' => 'Видеокарта', 'code' => 'gpu'],
|
||||||
|
['name' => 'Материнская плата', 'code' => 'motherboard'],
|
||||||
|
['name' => 'ОЗУ', 'code' => 'ram'],
|
||||||
|
['name' => 'Блок питания', 'code' => 'psu'],
|
||||||
|
['name' => 'SSD', 'code' => 'ssd'],
|
||||||
|
['name' => 'Корпус', 'code' => 'case'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('component_types');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreatePcBuildsTable extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('pc_builds', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('user_id')->constrained()->onDelete('cascade');
|
||||||
|
$table->string('name'); // Например: "Игровой ПК 2025"
|
||||||
|
$table->text('description')->nullable(); // Описание
|
||||||
|
$table->boolean('is_ai_generated')->default(false); // true = сгенерировано ИИ
|
||||||
|
$table->text('ai_prompt')->nullable(); // Исходный запрос к ИИ
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('pc_builds');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user