GroupInfo.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use Illuminate\Database\Eloquent\Relations\HasMany;
  7. /**
  8. * 团队(group)。表 `group_infos`,界面上叫「团队」,团队空间以它为 owner。
  9. *
  10. * `status`:30 公开(能被搜到、非成员也能看详情),10 私有(只有成员看得到)。
  11. */
  12. class GroupInfo extends Model
  13. {
  14. use HasFactory;
  15. protected $primaryKey = 'uid';
  16. /** 主键是 uuid:不声明的话关系预加载会按整数走 whereIntegerInRaw,把 uuid 全转成 0 */
  17. protected $keyType = 'string';
  18. protected $casts = [
  19. 'uid' => 'string',
  20. ];
  21. public const STATUS_PRIVATE = 10;
  22. public const STATUS_PUBLIC = 30;
  23. /**
  24. * 创建者(拥有者)。`owner` 是用户 uuid,对 `user_infos.userid`。
  25. */
  26. public function creator(): BelongsTo
  27. {
  28. return $this->belongsTo(UserInfo::class, 'owner', 'userid');
  29. }
  30. /**
  31. * 共享给这个团队的资源(「团队文档」)。`shares.cooperator_id` 对团队 uid。
  32. */
  33. public function shares(): HasMany
  34. {
  35. return $this->hasMany(Share::class, 'cooperator_id', 'uid');
  36. }
  37. /**
  38. * 团队成员。嵌套路由 `groups/{group}/members/{member}` 靠它做 scoped 绑定。
  39. */
  40. public function members(): HasMany
  41. {
  42. return $this->hasMany(GroupMember::class, 'group_id', 'uid');
  43. }
  44. }