InternalMessage.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class InternalMessage extends Model
  5. {
  6. protected $table = 'internal_message';
  7. public function getRouteKeyName()
  8. {
  9. return 'uid';
  10. }
  11. public function messageVideoFile()
  12. {
  13. return $this->hasOne(SystemFile::class, 'id', 'message_video_file_id');
  14. }
  15. public function fromPro()
  16. {
  17. return $this->hasOne(Pro::class, 'id', 'from_pro_id');
  18. }
  19. public function toPro()
  20. {
  21. return $this->hasOne(Pro::class, 'id', 'to_pro_id');
  22. }
  23. public function regardingClient()
  24. {
  25. return $this->hasOne(Client::class, 'id', 'regarding_client_id');
  26. }
  27. public function attachments()
  28. {
  29. return $this->hasMany(InternalMessageAttachment::class, 'internal_message_id', 'id');
  30. }
  31. public function readBy() {
  32. $readBy = '-';
  33. if($this->read_by_id) {
  34. $session = AppSession::where('id', $this->read_by_id)->first();
  35. switch($session->session_type) {
  36. case 'PRO':
  37. if($session->pro_id) {
  38. $pro = Pro::where('id', $session->pro_id)->first();
  39. if($pro) {
  40. $readBy = $pro->displayName() . ' (PRO)';
  41. }
  42. }
  43. break;
  44. case 'CLIENT':
  45. if($session->pro_id) {
  46. $client = Client::where('id', $session->client_id)->first();
  47. if($client) {
  48. $readBy = $client->displayName() . ' (CLIENT)';
  49. }
  50. }
  51. break;
  52. }
  53. }
  54. return $readBy;
  55. }
  56. }