模型关系设置
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
/**
|
||||
* 用户表
|
||||
@@ -13,4 +15,31 @@ class UserModal extends Model
|
||||
protected $table = 'users';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 项目关联 - 上传视角
|
||||
* @return HasMany
|
||||
*/
|
||||
public function projects(): HasMany
|
||||
{
|
||||
return $this->hasMany(ProjectModal::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目关联 - 作者视角
|
||||
* @return HasMany
|
||||
*/
|
||||
public function projectsAuthor(): HasMany
|
||||
{
|
||||
return $this->hasMany(ProjectModal::class, 'author_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色关联
|
||||
* @return HasOne
|
||||
*/
|
||||
public function roles(): HasOne
|
||||
{
|
||||
return $this->hasOne(RoleModal::class, 'id', 'role_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user