PetSkillLog.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Module\Pet\Models;
  3. use UCore\ModelCore;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. /**
  6. * 宠物技能使用日志模型
  7. *
  8. * field start
  9. * @property int $id
  10. * @property int $pet_id
  11. * @property int $skill_id
  12. * @property \Carbon\Carbon $used_at
  13. * @property array $effect_result 技能使用结果
  14. * @property \Carbon\Carbon $created_at
  15. * @property \Carbon\Carbon $updated_at
  16. * field end
  17. */
  18. class PetSkillLog extends ModelCore
  19. {
  20. /**
  21. * 与模型关联的表名
  22. *
  23. * @var string
  24. */
  25. protected $table = 'pet_skill_logs';
  26. /**
  27. * 指示模型是否应该被打上时间戳
  28. * 由于这是日志表,只需要创建时间,不需要更新时间
  29. *
  30. * @var bool
  31. */
  32. public $timestamps = true;
  33. /**
  34. * 更新时间戳字段名
  35. * 设置为null表示不使用updated_at字段
  36. *
  37. * @var string|null
  38. */
  39. const UPDATED_AT = null;
  40. // attrlist start
  41. protected $fillable = [
  42. 'id',
  43. 'pet_id',
  44. 'skill_id',
  45. 'used_at',
  46. 'effect_result',
  47. ];
  48. // attrlist end
  49. /**
  50. * 应该被转换为原生类型的属性
  51. *
  52. * @var array
  53. */
  54. protected $casts = [
  55. 'pet_id' => 'integer',
  56. 'skill_id' => 'integer',
  57. 'used_at' => 'datetime',
  58. 'created_at' => 'datetime',
  59. 'effect_result' => 'json',
  60. ];
  61. /**
  62. * 获取关联的宠物
  63. *
  64. * @return BelongsTo
  65. */
  66. public function pet(): BelongsTo
  67. {
  68. return $this->belongsTo(PetUser::class, 'pet_id');
  69. }
  70. /**
  71. * 获取关联的技能
  72. *
  73. * @return BelongsTo
  74. */
  75. public function skill(): BelongsTo
  76. {
  77. return $this->belongsTo(PetSkill::class, 'skill_id');
  78. }
  79. }