AppMessageRecipient.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * @property int $id
  24. * @property int $message_id 消息ID
  25. * @property int $user_id 用户ID
  26. * @property int $is_read 是否已读:0未读 1已读
  27. * @property string $read_at 阅读时间
  28. * @property int $status 状态:0删除 1正常
  29. * @property \Carbon\Carbon $created_at 创建时间
  30. * @property \Carbon\Carbon $updated_at 更新时间
  31. * field end
  32. */
  33. class AppMessageRecipient extends Model
  34. {
  35. /**
  36. * 数据表名称
  37. *
  38. * @var string
  39. */
  40. protected $table = 'app_message_recipients';
  41. // attrlist start
  42. protected $fillable = [
  43. 'id',
  44. 'message_id',
  45. 'user_id',
  46. 'is_read',
  47. 'read_at',
  48. 'status',
  49. ];
  50. // attrlist end
  51. /**
  52. * 属性类型转换
  53. *
  54. * @var array
  55. */
  56. protected $casts = [
  57. 'is_read' => 'boolean',
  58. 'read_at' => 'datetime'
  59. ];
  60. /**
  61. * 获取关联的消息
  62. *
  63. * 定义与消息模型的多对一关系
  64. *
  65. * @return BelongsTo
  66. */
  67. public function message(): BelongsTo
  68. {
  69. return $this->belongsTo(AppMessage::class, 'message_id');
  70. }
  71. /**
  72. * 获取关联的用户
  73. *
  74. * 定义与用户模型的多对一关系
  75. *
  76. * @return BelongsTo
  77. */
  78. public function user(): BelongsTo
  79. {
  80. return $this->belongsTo(User::class);
  81. }
  82. }