Relay.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Models;
  3. /**
  4. * DetectLog Model
  5. */
  6. class Relay extends Model
  7. {
  8. protected $connection = "default";
  9. protected $table = "relay";
  10. public function User()
  11. {
  12. $user = User::where("id", $this->attributes['user_id'])->first();
  13. if ($user == null) {
  14. Relay::where('id', '=', $this->attributes['id'])->delete();
  15. return null;
  16. } else {
  17. return $user;
  18. }
  19. }
  20. public function Source_Node()
  21. {
  22. $node = Node::where("id", $this->attributes['source_node_id'])->first();
  23. if ($node == null && $this->attributes['source_node_id'] != 0) {
  24. Relay::where('id', '=', $this->attributes['id'])->delete();
  25. return null;
  26. } else {
  27. return $node;
  28. }
  29. }
  30. public function Dist_Node()
  31. {
  32. if ($this->attributes['dist_node_id'] == -1) {
  33. return null;
  34. }
  35. $node = Node::where("id", $this->attributes['dist_node_id'])->first();
  36. if ($node == null) {
  37. Relay::where('id', '=', $this->attributes['id'])->delete();
  38. return null;
  39. } else {
  40. return $node;
  41. }
  42. }
  43. }