模型关系设置
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
/**
|
||||
* 项目表
|
||||
@@ -14,4 +17,75 @@ class ProjectModal extends Model
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 用户关联
|
||||
* @return HasOne
|
||||
*/
|
||||
public function user(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserModal::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 作者关联
|
||||
* @return HasOne
|
||||
*/
|
||||
public function author(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserModal::class, 'id', 'author_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签关联
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function labels(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(LabelModal::class, 'project_labels_relations', 'project_id', 'label_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 截图关联
|
||||
* @return HasMany
|
||||
*/
|
||||
public function screenshots(): HasMany
|
||||
{
|
||||
return $this->hasMany(ScreenshotModal::class, 'project_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 框架关联
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function frameworks(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(FrameworkModal::class, 'project_frameworks_relations', 'project_id', 'framework_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 技术栈关联
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function technologyStacks(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(TechnologyStackModal::class, 'project_technology_stacks_relations', 'project_id', 'technology_stack_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能关联
|
||||
* @return HasMany
|
||||
*/
|
||||
public function features(): HasMany
|
||||
{
|
||||
return $this->hasMany(FeatureModal::class, 'project_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类关联
|
||||
* @return HasOne
|
||||
*/
|
||||
public function category(): HasOne
|
||||
{
|
||||
return $this->hasOne(CategoryModal::class, 'id', 'category_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user