Files
componentsPC/app/Models/PCBuild.php

42 lines
948 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PcBuild extends Model
{
use HasFactory;
protected $fillable = [
'name',
'description',
'user_id',
];
// 👇 Связь "многие-ко-многим" с компонентами
public function components()
{
return $this->belongsToMany(Component::class, 'pc_build_components');
}
// Обратная связь
public function user()
{
return $this->belongsTo(User::class);
}
// Опционально: защита от ошибок, если сборка без пользователя
protected static function booted()
{
static::addGlobalScope('user', function ($query) {
if (auth()->check()) {
$query->where('user_id', auth()->id());
}
});
}
}