2022-03-05 16:02:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2022-05-09 07:39:03 +02:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
2022-03-05 16:02:12 +01:00
|
|
|
|
|
|
|
class Providers extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
protected $fillable = ['name'];
|
|
|
|
|
2022-07-22 15:49:18 +02:00
|
|
|
protected $keyType = 'string';
|
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
protected $table = 'providers';
|
2022-05-09 07:39:03 +02:00
|
|
|
|
|
|
|
public static function allProviders(): array
|
|
|
|
{
|
|
|
|
return Cache::remember("providers", now()->addMonth(1), function () {
|
2023-08-19 15:52:59 +02:00
|
|
|
return self::orderBy('name')->get()->toArray();
|
2022-05-09 07:39:03 +02:00
|
|
|
});
|
|
|
|
}
|
2022-05-15 13:01:02 +02:00
|
|
|
|
|
|
|
public static function showServicesForProvider($provider): array
|
|
|
|
{
|
|
|
|
$servers = DB::table('servers as s')
|
2023-08-18 11:33:26 +02:00
|
|
|
->where('s.provider_id', $provider)
|
2022-05-15 13:01:02 +02:00
|
|
|
->get(['s.id', 's.hostname'])
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
$shared = DB::table('shared_hosting as s')
|
2023-08-18 11:33:26 +02:00
|
|
|
->where('s.provider_id', $provider)
|
2022-05-15 13:01:02 +02:00
|
|
|
->get(['s.id', 's.main_domain as main_domain_shared'])
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
$reseller = DB::table('reseller_hosting as r')
|
2023-08-18 11:33:26 +02:00
|
|
|
->where('r.provider_id', $provider)
|
2022-05-15 13:01:02 +02:00
|
|
|
->get(['r.id', 'r.main_domain as main_domain_reseller'])
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
return array_merge($servers, $shared, $reseller);
|
|
|
|
}
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|