Skip to content

Commit

Permalink
Add migrations, factories and models
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisdelicata committed Jun 15, 2024
1 parent 6e42c98 commit 3a254ee
Show file tree
Hide file tree
Showing 19 changed files with 801 additions and 0 deletions.
49 changes: 49 additions & 0 deletions app/Models/DnsSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class DnsSetting extends Model
{
use HasFactory;

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'dns_settings';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'domain_id',
'record_type',
'name',
'value',
'ttl',
];

/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'ttl' => 'integer',
];

/**
* Get the domain that owns the DNS setting.
*/
public function domain()
{
return $this->belongsTo(Domain::class);
}
}

65 changes: 65 additions & 0 deletions app/Models/Domain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Domain extends Model
{
use HasFactory;

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'domains';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'domain_name',
'registration_date',
'expiration_date',
];

/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'registration_date' => 'date',
'expiration_date' => 'date',
];

/**
* Get the user that owns the domain.
*/
public function user()
{
return $this->belongsTo(User::class);
}

/**
* Get the email accounts for the domain.
*/
public function emailAccounts()
{
return $this->hasMany(EmailAccount::class);
}

/**
* Get the DNS settings for the domain.
*/
public function dnsSettings()
{
return $this->hasMany(DnsSetting::class);
}
}

48 changes: 48 additions & 0 deletions app/Models/EmailAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class EmailAccount extends Model
{
use HasFactory;

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'email_accounts';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'domain_id',
'email_address',
'password',
'quota',
];

/**
* Get the user that owns the email account.
*/
public function user()
{
return $this->belongsTo(User::class);
}

/**
* Get the domain that owns the email account.
*/
public function domain()
{
return $this->belongsTo(Domain::class);
}
}

57 changes: 57 additions & 0 deletions app/Models/HostingPlan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class HostingPlan extends Model
{
use HasFactory;

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'hosting_plans';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'description',
'disk_space',
'bandwidth',
'price',
];

/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'price' => 'decimal:2',
];

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'created_at',
'updated_at',
];

public function userHostingPlans()
{
return $this->hasMany(UserHostingPlan::class);
}

}

40 changes: 40 additions & 0 deletions app/Models/ResourceUsage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ResourceUsage extends Model
{
use HasFactory;

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'resource_usage';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'disk_usage',
'bandwidth_usage',
'month',
'year',
];

/**
* Get the user that owns the resource usage.
*/
public function user()
{
return $this->belongsTo(User::class);
}
}

25 changes: 25 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,29 @@ public function profilePhotoUrl(): Attribute
? Attribute::get(fn () => $this->profile_photo_path)
: $this->getPhotoUrl();
}

public function userHostingPlans()
{
return $this->hasMany(UserHostingPlan::class);
}

public function domains()
{
return $this->hasMany(Domain::class);
}

public function emailAccounts()
{
return $this->hasMany(EmailAccount::class);
}

public function resourceUsages()
{
return $this->hasMany(ResourceUsage::class);
}



}


57 changes: 57 additions & 0 deletions app/Models/UserHostingPlan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class UserHostingPlan extends Model
{
use HasFactory;

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'user_hosting_plans';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'hosting_plan_id',
'start_date',
'end_date',
];

/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'start_date' => 'date',
'end_date' => 'date',
];

/**
* Get the user that owns the hosting plan.
*/
public function user()
{
return $this->belongsTo(User::class);
}

/**
* Get the hosting plan associated with the user.
*/
public function hostingPlan()
{
return $this->belongsTo(HostingPlan::class);
}
}

39 changes: 39 additions & 0 deletions database/factories/DnsSettingFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Database\Factories;

use App\Models\DnsSetting;
use Illuminate\Database\Eloquent\Factories\Factory;

class DnsSettingFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = DnsSetting::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$recordTypes = ['A', 'CNAME', 'MX', 'TXT'];

return [
'domain_id' => function () {
return \App\Models\Domain::factory()->create()->id;
},
'record_type' => $this->faker->randomElement($recordTypes),
'name' => $this->faker->domainName,
'value' => $this->faker->ipv4,
'ttl' => $this->faker->numberBetween(300, 86400), // TTL between 300 seconds (5 minutes) and 86400 seconds (24 hours)
'created_at' => now(),
'updated_at' => now(),
];
}
}

Loading

0 comments on commit 3a254ee

Please sign in to comment.