| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace App\Models; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Illuminate\Database\Eloquent\Factories\HasFactory; | 
					
						
							|  |  |  | use Illuminate\Database\Eloquent\Model; | 
					
						
							| 
									
										
										
										
											2022-07-20 00:19:05 +10:00
										 |  |  | use Illuminate\Support\Facades\Cache; | 
					
						
							| 
									
										
										
										
											2022-10-20 13:57:04 +11:00
										 |  |  | use Illuminate\Support\Facades\Session; | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | class Domains extends Model | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     use HasFactory; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public $incrementing = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-20 00:19:05 +10:00
										 |  |  |     protected $table = 'domains'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-22 23:49:18 +10:00
										 |  |  |     protected $keyType = 'string'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  |     protected $fillable = ['id', 'domain', 'extension', 'ns1', 'ns2', 'ns3', 'price', 'currency', 'payment_term', 'owned_since', 'provider_id', 'next_due_date']; | 
					
						
							| 
									
										
										
										
											2022-05-15 16:22:47 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-20 00:19:05 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public static function allDomains() | 
					
						
							|  |  |  |     {//All domains and relationships (no using joins)
 | 
					
						
							|  |  |  |         return Cache::remember("all_domains", now()->addMonth(1), function () { | 
					
						
							| 
									
										
										
										
											2022-10-20 13:57:04 +11:00
										 |  |  |             $query = Domains::with(['provider', 'price', 'labels']); | 
					
						
							|  |  |  |             if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) { | 
					
						
							|  |  |  |                 $options = Settings::orderByProcess(Session::get('sort_on')); | 
					
						
							|  |  |  |                 $query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "domains.id"), $options[1]); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return $query->get(); | 
					
						
							| 
									
										
										
										
											2022-07-20 00:19:05 +10:00
										 |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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-10-13 13:43:09 +11:00
										 |  |  |                 ->with(['provider', 'price', 'labels'])->first(); | 
					
						
							| 
									
										
										
										
											2022-07-20 00:19:05 +10:00
										 |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-19 23:46:18 +10:00
										 |  |  |     public function provider(): \Illuminate\Database\Eloquent\Relations\HasOne | 
					
						
							| 
									
										
										
										
											2022-05-15 16:22:47 +10:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-07-20 00:19:05 +10:00
										 |  |  |         return $this->hasOne(Providers::class, 'id', 'provider_id'); | 
					
						
							| 
									
										
										
										
											2022-05-15 16:22:47 +10:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-19 23:46:18 +10:00
										 |  |  |     public function price(): \Illuminate\Database\Eloquent\Relations\HasOne | 
					
						
							| 
									
										
										
										
											2022-05-15 16:22:47 +10:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-07-20 00:19:05 +10:00
										 |  |  |         return $this->hasOne(Pricing::class, 'service_id', 'id'); | 
					
						
							| 
									
										
										
										
											2022-05-15 16:22:47 +10:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-19 23:46:18 +10:00
										 |  |  |     public function labels(): \Illuminate\Database\Eloquent\Relations\HasMany | 
					
						
							| 
									
										
										
										
											2022-05-15 16:22:47 +10:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-07-20 00:19:05 +10:00
										 |  |  |         return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); | 
					
						
							| 
									
										
										
										
											2022-05-15 16:22:47 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-07-20 00:19:05 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-02 13:57:28 +11:00
										 |  |  |     public function note(): \Illuminate\Database\Eloquent\Relations\HasOne | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->hasOne(Note::class, 'service_id', 'id'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 02:02:12 +11:00
										 |  |  | } |