KeysIdsTrait.php 894 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Traits;
  3. use App\Models\AppSession;
  4. trait KeysIdsTrait
  5. {
  6. public function getId ($object)
  7. {
  8. if( !$object) {
  9. return false;
  10. }
  11. if( !$object->id) {
  12. return false;
  13. }
  14. return $object->id;
  15. }
  16. public function getIid ($object)
  17. {
  18. if( !$object) {
  19. return false;
  20. }
  21. if( !$object->iid) {
  22. return false;
  23. }
  24. return $object->iid;
  25. }
  26. public function getUid ($object)
  27. {
  28. if( !$object) {
  29. return false;
  30. }
  31. if( !$object->uid) {
  32. return false;
  33. }
  34. return $object->uid;
  35. }
  36. public function saveForeignKey ($object)
  37. {
  38. return $object->id;
  39. }
  40. public function getCurrentSessionId ()
  41. {
  42. return request()->cookie("credo_session_key");
  43. }
  44. public function getCurrentAgentId ()
  45. {
  46. $sessionKey = $this->getCurrentSessionId();
  47. $appSession = AppSession::where("session_key", $sessionKey)->first();
  48. return $appSession->agent->uid;
  49. }
  50. }