PetBattleTeam.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Module\Pet\Models;
  3. use UCore\ModelCore;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. use Illuminate\Database\Eloquent\Relations\HasMany;
  6. /**
  7. * 宠物争霸赛队伍模型
  8. *
  9. * field start
  10. * @property int $id
  11. * @property int $season_id 赛季ID
  12. * @property string $name 队伍名称
  13. * @property int $leader_id 队长用户ID
  14. * @property int $total_power 队伍总战力
  15. * @property int $member_count 成员数量
  16. * @property \Carbon\Carbon $created_at
  17. * @property \Carbon\Carbon $updated_at
  18. * field end
  19. */
  20. class PetBattleTeam extends ModelCore
  21. {
  22. /**
  23. * 与模型关联的表名
  24. *
  25. * @var string
  26. */
  27. protected $table = 'pet_battle_teams';
  28. // attrlist start
  29. protected $fillable = [
  30. 'id',
  31. 'season_id',
  32. 'name',
  33. 'leader_id',
  34. 'total_power',
  35. 'member_count',
  36. ];
  37. // attrlist end
  38. /**
  39. * 应该被转换为原生类型的属性
  40. *
  41. * @var array
  42. */
  43. protected $casts = [
  44. 'season_id' => 'integer',
  45. 'leader_id' => 'integer',
  46. 'total_power' => 'integer',
  47. 'member_count' => 'integer',
  48. ];
  49. /**
  50. * 获取关联的赛季
  51. *
  52. * @return BelongsTo
  53. */
  54. public function season(): BelongsTo
  55. {
  56. return $this->belongsTo(PetBattleSeason::class, 'season_id');
  57. }
  58. /**
  59. * 获取队伍的所有成员
  60. *
  61. * @return HasMany
  62. */
  63. public function members(): HasMany
  64. {
  65. return $this->hasMany(PetBattleTeamMember::class, 'team_id');
  66. }
  67. /**
  68. * 获取队长用户
  69. *
  70. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  71. */
  72. public function leader()
  73. {
  74. return $this->belongsTo(\App\Models\User::class, 'leader_id');
  75. }
  76. }