DomainRelations.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\dns\submodules\GoogleCloud;
  3. use \Illuminate\Database\Eloquent\model as EloquentModel;
  4. use \Illuminate\Database\Schema\Blueprint;
  5. use \WHMCS\Database\Capsule;
  6. /**
  7. * Description of TaskHistory
  8. *
  9. * @author Mateusz Pawłowski <mateusz.pa@modulesgarden.com>
  10. *
  11. *
  12. * @method public static WhereDomain(string $domain)
  13. * @method public static WhereName(string $name)
  14. *
  15. * @property int $id
  16. * @property int $hosting_id
  17. * @property string $task
  18. */
  19. class DomainRelations extends EloquentModel
  20. {
  21. /*
  22. * Table name
  23. *
  24. * @var string $table
  25. */
  26. protected $table = 'dns_manager2_googlecloud_domains';
  27. /**
  28. * Eloquent fillable parameters
  29. * @var array
  30. */
  31. protected $fillable = ['domain', 'name'];
  32. /*
  33. * Scope to get task where hosting ID
  34. *
  35. * @param integer $serviceID
  36. */
  37. public function scopeWhereDomain($query, $domain)
  38. {
  39. return $query->where('domain', $domain);
  40. }
  41. public function scopeWhereName($query, $name)
  42. {
  43. return $query->where('name', $name);
  44. }
  45. //////////////////////////// Create Table //////////////////////////////////////
  46. /*
  47. * Check table exist
  48. *
  49. * @return boolean
  50. */
  51. public function tableExists()
  52. {
  53. return Capsule::Schema()->hasTable($this->table);
  54. }
  55. /*
  56. * Create table
  57. *
  58. * @return void
  59. */
  60. protected function createTable()
  61. {
  62. Capsule::schema()->create($this->table, function (Blueprint $table)
  63. {
  64. $table->charset = 'utf8';
  65. $table->collation = 'utf8_general_ci';
  66. $table->increments('id')->unique();
  67. $table->string('domain', 255);
  68. $table->string('name', 255);
  69. $table->timestamps();
  70. });
  71. }
  72. /*
  73. * Check and create if not exist
  74. *
  75. * @return void
  76. */
  77. public function createTableIfNotExists()
  78. {
  79. if (!$this->tableExists())
  80. {
  81. $this->createTable();
  82. }
  83. }
  84. }