ChatMessage.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use Illuminate\Database\Eloquent\Relations\BelongsToMany;
  7. class ChatMessage extends Model
  8. {
  9. use HasFactory;
  10. public const NOTIFICATION_NONE = 'none';
  11. public const NOTIFICATION_RESPONSIBLES = 'responsibles';
  12. public const NOTIFICATION_ALL = 'all';
  13. public const NOTIFICATION_USER = 'user';
  14. public const NOTIFICATION_TYPE_NAMES = [
  15. self::NOTIFICATION_NONE => 'Нет',
  16. self::NOTIFICATION_RESPONSIBLES => 'Админы, менеджер, бригадир',
  17. self::NOTIFICATION_ALL => 'Все',
  18. self::NOTIFICATION_USER => 'Конкретному пользователю',
  19. ];
  20. protected $fillable = [
  21. 'order_id',
  22. 'reclamation_id',
  23. 'production_order_id',
  24. 'user_id',
  25. 'target_user_id',
  26. 'notification_type',
  27. 'message',
  28. ];
  29. public function order(): BelongsTo
  30. {
  31. return $this->belongsTo(Order::class);
  32. }
  33. public function reclamation(): BelongsTo
  34. {
  35. return $this->belongsTo(Reclamation::class);
  36. }
  37. public function productionOrder(): BelongsTo
  38. {
  39. return $this->belongsTo(ProductionOrder::class);
  40. }
  41. public function user(): BelongsTo
  42. {
  43. return $this->belongsTo(User::class);
  44. }
  45. public function targetUser(): BelongsTo
  46. {
  47. return $this->belongsTo(User::class, 'target_user_id');
  48. }
  49. public function notifiedUsers(): BelongsToMany
  50. {
  51. return $this->belongsToMany(User::class, 'chat_message_user');
  52. }
  53. public function files(): BelongsToMany
  54. {
  55. return $this->belongsToMany(File::class, 'chat_message_file')->withTimestamps();
  56. }
  57. }