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

46 lines
862 B
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\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
2025-04-28 16:15:09 +08:00
/**
* 用户表
*/
2025-05-05 09:44:50 +08:00
class UserModel extends BaseModel
2025-04-28 16:15:09 +08:00
{
//
protected $table = 'users';
protected $guarded = [];
2025-04-28 16:45:23 +08:00
/**
* 项目关联 - 上传视角
* @return HasMany
*/
public function projects(): HasMany
{
2025-05-05 09:44:50 +08:00
return $this->hasMany(ProjectModel::class, 'user_id', 'id');
2025-04-28 16:45:23 +08:00
}
/**
* 项目关联 - 作者视角
* @return HasMany
*/
public function projectsAuthor(): HasMany
{
2025-05-05 09:44:50 +08:00
return $this->hasMany(ProjectModel::class, 'author_id', 'id');
2025-04-28 16:45:23 +08:00
}
/**
* 角色关联
* @return HasOne
*/
public function roles(): HasOne
{
2025-05-05 09:44:50 +08:00
return $this->hasOne(RoleModel::class, 'id', 'role_id');
2025-04-28 16:45:23 +08:00
}
2025-04-28 16:15:09 +08:00
}