Files
spa-api/app/Models/ProjectModel.php

92 lines
2.0 KiB
PHP
Raw Normal View History

2025-04-28 16:15:09 +08:00
<?php
namespace App\Models;
2025-05-05 09:44:50 +08:00
use App\BaseApp\BaseModel;
2025-04-28 16:45:23 +08:00
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
2025-04-28 16:15:09 +08:00
/**
* 项目表
*/
2025-05-05 09:44:50 +08:00
class ProjectModel extends BaseModel
2025-04-28 16:15:09 +08:00
{
//
protected $table = 'projects';
protected $guarded = [];
2025-04-28 16:45:23 +08:00
/**
* 用户关联
* @return HasOne
*/
public function user(): HasOne
{
2025-05-05 09:44:50 +08:00
return $this->hasOne(UserModel::class, 'id', 'user_id');
2025-04-28 16:45:23 +08:00
}
/**
* 作者关联
* @return HasOne
*/
public function author(): HasOne
{
2025-05-05 09:44:50 +08:00
return $this->hasOne(UserModel::class, 'id', 'author_id');
2025-04-28 16:45:23 +08:00
}
/**
* 标签关联
* @return BelongsToMany
*/
public function labels(): BelongsToMany
{
2025-05-05 09:44:50 +08:00
return $this->belongsToMany(LabelModel::class, 'project_label_relations', 'project_id', 'label_id');
2025-04-28 16:45:23 +08:00
}
/**
* 截图关联
* @return HasMany
*/
public function screenshots(): HasMany
{
2025-05-05 09:44:50 +08:00
return $this->hasMany(ScreenshotModel::class, 'project_id', 'id');
2025-04-28 16:45:23 +08:00
}
/**
* 框架关联
* @return BelongsToMany
*/
public function frameworks(): BelongsToMany
{
2025-05-05 09:44:50 +08:00
return $this->belongsToMany(FrameworkModel::class, 'project_frameworks_relations', 'project_id', 'framework_id');
2025-04-28 16:45:23 +08:00
}
/**
* 技术栈关联
* @return BelongsToMany
*/
public function technologyStacks(): BelongsToMany
{
2025-05-05 09:44:50 +08:00
return $this->belongsToMany(TechnologyStackModel::class, 'project_technology_stacks_relations', 'project_id', 'technology_stacks_id');
2025-04-28 16:45:23 +08:00
}
/**
* 功能关联
* @return HasMany
*/
public function features(): HasMany
{
2025-05-05 09:44:50 +08:00
return $this->hasMany(FeatureModel::class, 'project_id', 'id');
2025-04-28 16:45:23 +08:00
}
/**
* 分类关联
* @return HasOne
*/
public function category(): HasOne
{
2025-05-05 09:44:50 +08:00
return $this->hasOne(CategoryModel::class, 'id', 'category_id');
2025-04-28 16:45:23 +08:00
}
2025-04-28 16:15:09 +08:00
}