McpRequest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Models;
  3. use Carbon\Carbon;
  4. use DateTime;
  5. # use Illuminate\Database\Eloquent\Model;
  6. class McpRequest extends Model
  7. {
  8. protected $table = 'mcp_request';
  9. public function client()
  10. {
  11. return $this->hasOne(Client::class, 'id', 'for_client_id');
  12. }
  13. public function proClientWork()
  14. {
  15. return $this->hasOne(ProClientWork::class, 'id', 'mcp_pro_client_work_id');
  16. }
  17. public function createdBy()
  18. {
  19. return $this->hasOne(AppSession::class, 'id', 'created_by_session_id');
  20. }
  21. public function createdByName(){
  22. $performer = $this->createdBy;
  23. if($performer->session_type == 'PRO'){
  24. return $performer->pro->name_first.' '.$performer->pro->name_last;
  25. }
  26. if($performer->session_type == 'CLIENT_GUEST'){
  27. return $performer->client->name_first.' '.$performer->client->name_last;
  28. }
  29. return "-";
  30. }
  31. public function getWaitTime(){
  32. if(!$this->was_claimed){
  33. return "-";
  34. }
  35. $created_at = new Carbon($this->created_at);
  36. $claimed_at = new Carbon($this->proClientWork->created_at);
  37. return $claimed_at->diffForHumans($created_at);
  38. }
  39. }