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