VirtualInterface.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. */
  22. class VirtualInterface extends ExtendedEloquentModel
  23. {
  24. /** @var string */
  25. protected $table = 'VirtualInterface';
  26. protected $fillable = [ 'hosting_id','vn_id', 'vm_id', 'ip', 'ip_long','net',
  27. ];
  28. public $timestamps = false;
  29. public function scopeOfHostingId($query, $hostingId)
  30. {
  31. return $query->where("hosting_id", $hostingId);
  32. }
  33. public function scopeOfVirtualNetworkId($query, $networkId)
  34. {
  35. return $query->where("vn_id", $networkId);
  36. }
  37. public function scopeOfVmId($query, $id)
  38. {
  39. return $query->where("vm_id", $id);
  40. }
  41. public function scopeOfVnId($query, $id)
  42. {
  43. return $query->where("vn_id", $id);
  44. }
  45. public function scopeOfIp($query, $ip)
  46. {
  47. return $query->where("ip", $ip);
  48. }
  49. public function virtualNetwork()
  50. {
  51. return $this->belongsTo(VirtualNetwork::class, "vn_id");
  52. }
  53. public function vmModel()
  54. {
  55. return $this->belongsTo(VmModel::class, "vm_id");
  56. }
  57. public function scopeNotId($query, $ips)
  58. {
  59. return $query->whereNotIn("id", $ips);
  60. }
  61. public function scopeOfNetEmpty($query)
  62. {
  63. return $query->where("net", "");
  64. }
  65. public function scopeOfNet($query , $net)
  66. {
  67. return $query->where("net", $net);
  68. }
  69. }