Client.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Relations\HasOne;
  4. # use Illuminate\Database\Eloquent\Model;
  5. class Client extends Model
  6. {
  7. protected $table = 'client';
  8. public function displayName() {
  9. return $this->name_last . ', '. $this->name_first;
  10. }
  11. public function mcp() {
  12. return $this->hasOne(Pro::class, 'id', 'mcp_pro_id');
  13. }
  14. public function cm() {
  15. return $this->hasOne(Pro::class, 'id', 'cm_pro_id');
  16. }
  17. public function prosInMeetingWith() {
  18. return Pro::where('in_meeting_with_client_id', $this->id)->get();
  19. }
  20. public function notes() {
  21. return $this->hasMany(Note::class, 'client_id', 'id')->orderBy('created_at', 'desc');
  22. }
  23. public function duplicateOf() {
  24. return $this->hasOne(Client::class, 'id', 'duplicate_of_client_id');
  25. }
  26. public function actionItems () {
  27. return $this->hasMany(ActionItem::class, 'client_id', 'id')
  28. ->orderBy('action_item_category', 'asc')
  29. ->orderBy('created_at', 'desc');
  30. }
  31. public function infoLines() {
  32. return $this->hasMany(ClientInfoLine::class, 'client_id', 'id')->orderBy('created_at', 'desc');
  33. }
  34. public function measurements() {
  35. return $this->hasMany(Measurement::class, 'client_id', 'id')
  36. ->distinct('label')
  37. ->where('is_removed', false)
  38. ->orderBy('label', 'asc')
  39. ->orderBy('created_at', 'desc');
  40. }
  41. public function smses() {
  42. return $this->hasMany(ClientSMS::class, 'client_id', 'id')
  43. ->orderBy('created_at', 'desc');
  44. }
  45. public function documents() {
  46. return $this->hasMany(ClientDocument::class, 'client_id', 'id')
  47. ->orderBy('created_at', 'desc');
  48. }
  49. public function smsNumbers() {
  50. return $this->hasMany(ClientSMSNumber::class, 'client_id', 'id')
  51. ->orderBy('created_at', 'desc');
  52. }
  53. }