osb/app/Models/Supplier/Domain.php

56 lines
1.0 KiB
PHP

<?php
namespace App\Models\Supplier;
use Illuminate\Support\Collection;
use App\Interfaces\SupplierItem;
use App\Models\Product\Domain as ProductDomain;
use App\Models\TLD;
final class Domain extends Type implements SupplierItem
{
protected const category_name = 'Domain Name';
protected $table = 'supplier_domain';
/* INTERFACES */
public function getBillingIntervalAttribute(): int
{
return 4; // Yearly
}
public function getNameAttribute(): string
{
return sprintf('%s: %s',$this->product_id,$this->tld->name);
}
public function products()
{
return $this->hasMany(ProductDomain::class,'supplier_item_id','id');
}
/* STATIC */
/**
* Determine the owner of the name servers used for the domain
*
*/
public static function nameserver_name(Collection $nameservers): string
{
foreach (config('nameservers') as $key => $ns) {
if ($nameservers->diff($ns)->count() < count($ns))
return $key;
}
return 'custom';
}
/* RELATIONS */
public function tld()
{
return $this->belongsTo(TLD::class);
}
}