ChatMessage.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. 'user_id',
  24. 'target_user_id',
  25. 'notification_type',
  26. 'message',
  27. ];
  28. public function order(): BelongsTo
  29. {
  30. return $this->belongsTo(Order::class);
  31. }
  32. public function reclamation(): BelongsTo
  33. {
  34. return $this->belongsTo(Reclamation::class);
  35. }
  36. public function user(): BelongsTo
  37. {
  38. return $this->belongsTo(User::class);
  39. }
  40. public function targetUser(): BelongsTo
  41. {
  42. return $this->belongsTo(User::class, 'target_user_id');
  43. }
  44. public function files(): BelongsToMany
  45. {
  46. return $this->belongsToMany(File::class, 'chat_message_file')->withTimestamps();
  47. }
  48. }