Начальный коммит: рабочая версия с исправленной авторизацией
This commit is contained in:
58
app/Models/AiTask.php
Normal file
58
app/Models/AiTask.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AiTask extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
<<<<<<< HEAD
|
||||
'title',
|
||||
'description',
|
||||
'ai_prompt_template',
|
||||
'budget_min',
|
||||
'budget_max',
|
||||
'is_active'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'budget_min' => 'decimal:2',
|
||||
'budget_max' => 'decimal:2',
|
||||
'is_active' => 'boolean'
|
||||
];
|
||||
=======
|
||||
'user_id',
|
||||
'name',
|
||||
'prompt_template',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
// Связь с пользователем (если шаблон пользовательский)
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
// Общие (глобальные) шаблоны — где user_id IS NULL
|
||||
public function scopeGlobal($query)
|
||||
{
|
||||
return $query->whereNull('user_id');
|
||||
}
|
||||
|
||||
// Активные шаблоны
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
>>>>>>> origin/main
|
||||
}
|
||||
34
app/Models/Component.php
Normal file
34
app/Models/Component.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
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',
|
||||
];
|
||||
}
|
||||
55
app/Models/PCBuild.php
Normal file
55
app/Models/PCBuild.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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',
|
||||
|
||||
|
||||
];
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 👇 Связь "многие-ко-многим" с компонентами
|
||||
public function components()
|
||||
{
|
||||
return $this->belongsToMany(Component::class, 'pc_build_components');
|
||||
}
|
||||
|
||||
// Обратная связь
|
||||
=======
|
||||
protected $casts = [
|
||||
'is_ai_generated' => 'boolean',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
// Связь с пользователем
|
||||
>>>>>>> origin/main
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
// Опционально: защита от ошибок, если сборка без пользователя
|
||||
protected static function booted()
|
||||
{
|
||||
static::addGlobalScope('user', function ($query) {
|
||||
if (auth()->check()) {
|
||||
$query->where('user_id', auth()->id());
|
||||
}
|
||||
});
|
||||
}
|
||||
=======
|
||||
>>>>>>> origin/main
|
||||
}
|
||||
35
app/Models/PCBuildComponent.php
Normal file
35
app/Models/PCBuildComponent.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PcBuildComponent extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'pc_build_id',
|
||||
'component_id',
|
||||
'quantity',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'quantity' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
// Связь с сборкой
|
||||
public function build()
|
||||
{
|
||||
return $this->belongsTo(PcBuild::class);
|
||||
}
|
||||
|
||||
// Связь с компонентом
|
||||
public function component()
|
||||
{
|
||||
return $this->belongsTo(Component::class);
|
||||
}
|
||||
}
|
||||
52
app/Models/User.php
Normal file
52
app/Models/User.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
|
||||
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'custom_field'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user