AppMessageRecipient.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. class AppMessageRecipient extends Model
  20. {
  21. /**
  22. * 数据表名称
  23. *
  24. * @var string
  25. */
  26. protected $table = 'app_message_recipients';
  27. /**
  28. * 可批量赋值的属性
  29. *
  30. * @var array
  31. */
  32. protected $fillable = [
  33. 'message_id', // 消息ID
  34. 'user_id', // 用户ID
  35. 'is_read', // 是否已读
  36. 'read_at' // 阅读时间
  37. ];
  38. /**
  39. * 属性类型转换
  40. *
  41. * @var array
  42. */
  43. protected $casts = [
  44. 'is_read' => 'boolean',
  45. 'read_at' => 'datetime'
  46. ];
  47. /**
  48. * 获取关联的消息
  49. *
  50. * 定义与消息模型的多对一关系
  51. *
  52. * @return BelongsTo
  53. */
  54. public function message(): BelongsTo
  55. {
  56. return $this->belongsTo(AppMessage::class, 'message_id');
  57. }
  58. /**
  59. * 获取关联的用户
  60. *
  61. * 定义与用户模型的多对一关系
  62. *
  63. * @return BelongsTo
  64. */
  65. public function user(): BelongsTo
  66. {
  67. return $this->belongsTo(User::class);
  68. }
  69. }