2019-06-07 06:54:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models\Service;
|
|
|
|
|
2021-07-13 02:31:56 +00:00
|
|
|
use Carbon\Carbon;
|
|
|
|
|
2020-02-19 12:37:45 +00:00
|
|
|
use App\Models\Base\ServiceType;
|
2021-07-13 02:31:56 +00:00
|
|
|
use App\Models\{Account,DomainRegistrar,DomainTld,Service};
|
2020-02-19 12:37:45 +00:00
|
|
|
use App\Interfaces\ServiceItem;
|
2021-07-13 02:31:56 +00:00
|
|
|
use App\Traits\{NextKey,ScopeServiceActive,ScopeServiceUserAuthorised};
|
2019-06-13 04:32:34 +00:00
|
|
|
|
2021-07-13 02:31:56 +00:00
|
|
|
/**
|
|
|
|
* Class Domain (Service)
|
|
|
|
* Services that domain names
|
|
|
|
*
|
|
|
|
* Attributes for services:
|
|
|
|
* + service_description : Description as shown in a Service Context
|
|
|
|
* + service_expire : The date the service expires
|
|
|
|
* + service_name : Name as shown in a Service Context
|
|
|
|
*
|
|
|
|
* @package App\Models\Service
|
|
|
|
*/
|
2020-02-19 12:37:45 +00:00
|
|
|
class Domain extends ServiceType implements ServiceItem
|
2019-06-07 06:54:27 +00:00
|
|
|
{
|
2021-07-13 02:31:56 +00:00
|
|
|
use ScopeServiceActive,ScopeServiceUserAuthorised;
|
2019-06-13 04:32:34 +00:00
|
|
|
|
2020-02-19 12:37:45 +00:00
|
|
|
protected $dates = [
|
|
|
|
'domain_expire',
|
|
|
|
];
|
2021-07-13 02:31:56 +00:00
|
|
|
protected $table = 'service_domains';
|
2020-02-10 11:07:46 +00:00
|
|
|
protected $with = ['tld'];
|
2019-06-07 06:54:27 +00:00
|
|
|
|
2021-07-13 02:31:56 +00:00
|
|
|
/* RELATIONS */
|
|
|
|
|
|
|
|
public function account()
|
|
|
|
{
|
|
|
|
return $this->hasOneThrough(Account::class,Service::class);
|
|
|
|
}
|
|
|
|
|
2020-02-19 12:37:45 +00:00
|
|
|
public function registrar()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(DomainRegistrar::class,'domain_registrar_id');
|
|
|
|
}
|
|
|
|
|
2019-06-07 06:54:27 +00:00
|
|
|
public function tld()
|
|
|
|
{
|
2020-02-19 12:37:45 +00:00
|
|
|
return $this->belongsTo(DomainTld::class,'domain_tld_id');
|
|
|
|
}
|
|
|
|
|
2021-07-13 02:31:56 +00:00
|
|
|
/* SCOPES */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for a record
|
|
|
|
*
|
|
|
|
* @param $query
|
|
|
|
* @param string $term
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function scopeSearch($query,string $term)
|
|
|
|
{
|
|
|
|
// If we have a period in the name, we'll ignore everything after it.
|
|
|
|
$term = strstr($term,'.',TRUE) ?: $term;
|
|
|
|
|
|
|
|
// Build our where clause
|
|
|
|
return parent::scopeSearch($query,$term)
|
|
|
|
->orwhere('domain_name','like','%'.$term.'%');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ATTRIBUTES */
|
|
|
|
|
2020-02-19 12:37:45 +00:00
|
|
|
public function getServiceDescriptionAttribute(): string
|
|
|
|
{
|
|
|
|
// N/A
|
2020-02-20 11:54:28 +00:00
|
|
|
return 'Domain Name';
|
2020-02-19 12:37:45 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 02:31:56 +00:00
|
|
|
public function getServiceExpireAttribute(): Carbon
|
|
|
|
{
|
|
|
|
return $this->domain_expire;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of the domain with its TLD
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2020-02-19 12:37:45 +00:00
|
|
|
public function getServiceNameAttribute(): string
|
|
|
|
{
|
2021-07-13 02:31:56 +00:00
|
|
|
return strtoupper(sprintf('%s.%s',$this->domain_name,$this->tld->name));
|
2019-06-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
2020-02-19 12:37:45 +00:00
|
|
|
public function inContract(): bool
|
2019-06-07 06:54:27 +00:00
|
|
|
{
|
2020-02-19 12:37:45 +00:00
|
|
|
return $this->domain_expire->isFuture();
|
2019-06-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
}
|