VirtualInterface.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Models;
  3. use ModulesGarden\ProxmoxAddon\Core\Models\ExtendedEloquentModel;
  4. /**
  5. * @property int $id
  6. * @property int $hosting_id
  7. * @property int $vn_id
  8. * @property int $vm_id
  9. * @property string $ip
  10. * @property int $ip_long
  11. * @property string $net
  12. * @property VirtualNetwork $virtualNetwork
  13. * @property VmModel $vmModel
  14. * @method static $this ofHostingId($hostingId)
  15. * @method $this ofVnId($hostingId)
  16. * @method $this ofVmId($id)
  17. * @method $this ofIp($ip)
  18. * @method $this notId($ids)
  19. * @method $this ofNetEmpty($ids)
  20. * @method $this ofNet($net)
  21. * @method $this ofVmIds($ids)
  22. * @method $this notPublic()
  23. */
  24. class VirtualInterface extends ExtendedEloquentModel
  25. {
  26. /** @var string */
  27. protected $table = 'VirtualInterface';
  28. protected $fillable = [ 'hosting_id','vn_id', 'vm_id', 'ip', 'ip_long','net',
  29. ];
  30. public $timestamps = false;
  31. public function scopeOfHostingId($query, $hostingId)
  32. {
  33. return $query->where("hosting_id", $hostingId);
  34. }
  35. public function scopeOfVirtualNetworkId($query, $networkId)
  36. {
  37. return $query->where("vn_id", $networkId);
  38. }
  39. public function scopeOfVmId($query, $id)
  40. {
  41. return $query->where("vm_id", $id);
  42. }
  43. public function scopeOfVnId($query, $id)
  44. {
  45. return $query->where("vn_id", $id);
  46. }
  47. public function scopeOfIp($query, $ip)
  48. {
  49. return $query->where("ip", $ip);
  50. }
  51. public function virtualNetwork()
  52. {
  53. return $this->belongsTo(VirtualNetwork::class, "vn_id");
  54. }
  55. public function vmModel()
  56. {
  57. return $this->belongsTo(VmModel::class, "vm_id");
  58. }
  59. public function scopeNotId($query, $ips)
  60. {
  61. return $query->whereNotIn("id", $ips);
  62. }
  63. public function scopeOfNetEmpty($query)
  64. {
  65. return $query->where("net", "");
  66. }
  67. public function scopeOfNet($query , $net)
  68. {
  69. return $query->where("net", $net);
  70. }
  71. public function scopeOfVmIds($query, $ids)
  72. {
  73. return $query->whereIn("vm_id", $ids);
  74. }
  75. public function scopeNotPublic($query)
  76. {
  77. return $query->where("vn_id", "!=", "0");
  78. }
  79. }