AppMessageRecipient.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Module\Ulogic\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. /**
  6. * 应用消息接收者模型
  7. *
  8. * @property int $id 接收记录ID
  9. * @property int $message_id 消息ID
  10. * @property int $user_id 用户ID
  11. * @property bool $is_read 是否已读
  12. * @property \Carbon\Carbon|null $read_at 阅读时间
  13. * @property \Carbon\Carbon $created_at 创建时间
  14. * @property \Carbon\Carbon $updated_at 更新时间
  15. *
  16. * @property-read AppMessage $message 关联的消息
  17. * @property-read \App\Models\User $user 关联的用户
  18. */
  19. /**
  20. * App\Module\Ulogic\Models\AppMessageRecipient
  21. *
  22. * field start
  23. * field end
  24. */
  25. class AppMessageRecipient extends Model
  26. {
  27. /**
  28. * 数据表名称
  29. *
  30. * @var string
  31. */
  32. protected $table = 'app_message_recipients';
  33. // attrlist start
  34. protected $fillable = [
  35. ];
  36. // attrlist end
  37. /**
  38. * 可批量赋值的属性
  39. *
  40. * @var array
  41. */
  42. protected $fillable = [
  43. 'message_id', // 消息ID
  44. 'user_id', // 用户ID
  45. 'is_read', // 是否已读
  46. 'read_at' // 阅读时间
  47. ];
  48. /**
  49. * 属性类型转换
  50. *
  51. * @var array
  52. */
  53. protected $casts = [
  54. 'is_read' => 'boolean',
  55. 'read_at' => 'datetime'
  56. ];
  57. /**
  58. * 获取关联的消息
  59. *
  60. * 定义与消息模型的多对一关系
  61. *
  62. * @return BelongsTo
  63. */
  64. public function message(): BelongsTo
  65. {
  66. return $this->belongsTo(AppMessage::class, 'message_id');
  67. }
  68. /**
  69. * 获取关联的用户
  70. *
  71. * 定义与用户模型的多对一关系
  72. *
  73. * @return BelongsTo
  74. */
  75. public function user(): BelongsTo
  76. {
  77. return $this->belongsTo(User::class);
  78. }
  79. }