2022-03-05 16:02:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2022-07-19 16:19:05 +02:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-05-15 08:22:47 +02:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2022-03-05 16:02:12 +01:00
|
|
|
|
|
|
|
class Domains extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
public $incrementing = false;
|
|
|
|
|
2022-07-19 16:19:05 +02:00
|
|
|
protected $table = 'domains';
|
|
|
|
|
2022-07-22 15:49:18 +02:00
|
|
|
protected $keyType = 'string';
|
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
protected $fillable = ['id', 'domain', 'extension', 'ns1', 'ns2', 'ns3', 'price', 'currency', 'payment_term', 'owned_since', 'provider_id', 'next_due_date'];
|
2022-05-15 08:22:47 +02:00
|
|
|
|
2022-07-19 16:19:05 +02:00
|
|
|
|
|
|
|
public static function allDomains()
|
|
|
|
{//All domains and relationships (no using joins)
|
|
|
|
return Cache::remember("all_domains", now()->addMonth(1), function () {
|
|
|
|
return Domains::with(['provider', 'price', 'labels', 'labels.label'])->get();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function domain(string $domain_id)
|
|
|
|
{//Single domains and relationships (no using joins)
|
|
|
|
return Cache::remember("domain.$domain_id", now()->addMonth(1), function () use ($domain_id) {
|
|
|
|
return Domains::where('id', $domain_id)
|
2022-09-22 05:20:23 +02:00
|
|
|
->with(['provider', 'price', 'labels', 'labels.label'])->first();
|
2022-07-19 16:19:05 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provider()
|
2022-05-15 08:22:47 +02:00
|
|
|
{
|
2022-07-19 16:19:05 +02:00
|
|
|
return $this->hasOne(Providers::class, 'id', 'provider_id');
|
2022-05-15 08:22:47 +02:00
|
|
|
}
|
|
|
|
|
2022-07-19 16:19:05 +02:00
|
|
|
public function price()
|
2022-05-15 08:22:47 +02:00
|
|
|
{
|
2022-07-19 16:19:05 +02:00
|
|
|
return $this->hasOne(Pricing::class, 'service_id', 'id');
|
2022-05-15 08:22:47 +02:00
|
|
|
}
|
|
|
|
|
2022-07-19 16:19:05 +02:00
|
|
|
public function labels()
|
2022-05-15 08:22:47 +02:00
|
|
|
{
|
2022-07-19 16:19:05 +02:00
|
|
|
return $this->hasMany(LabelsAssigned::class, 'service_id', 'id');
|
2022-05-15 08:22:47 +02:00
|
|
|
}
|
2022-07-19 16:19:05 +02:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|