Updated Providers controller

Moved show functions into model
This commit is contained in:
cp6 2022-05-15 21:01:02 +10:00
parent 4cf38ba45c
commit e4f0d95128
2 changed files with 21 additions and 16 deletions

View File

@ -39,22 +39,7 @@ class ProvidersController extends Controller
public function show(Providers $provider) public function show(Providers $provider)
{ {
$servers = DB::table('servers as s') $data = Providers::showServicesForProvider($provider->id);
->where('s.provider_id', '=', $provider->id)
->get(['s.id', 's.hostname'])
->toArray();
$shared = DB::table('shared_hosting as s')
->where('s.provider_id', '=', $provider->id)
->get(['s.id', 's.main_domain as main_domain_shared'])
->toArray();
$reseller = DB::table('reseller_hosting as r')
->where('r.provider_id', '=', $provider->id)
->get(['r.id', 'r.main_domain as main_domain_reseller'])
->toArray();
$data = array_merge($servers, $shared, $reseller);
return view('providers.show', compact(['provider', 'data'])); return view('providers.show', compact(['provider', 'data']));
} }

View File

@ -21,4 +21,24 @@ class Providers extends Model
return DB::table('providers')->get()->toArray(); return DB::table('providers')->get()->toArray();
}); });
} }
public static function showServicesForProvider($provider): array
{
$servers = DB::table('servers as s')
->where('s.provider_id', '=', $provider)
->get(['s.id', 's.hostname'])
->toArray();
$shared = DB::table('shared_hosting as s')
->where('s.provider_id', '=', $provider)
->get(['s.id', 's.main_domain as main_domain_shared'])
->toArray();
$reseller = DB::table('reseller_hosting as r')
->where('r.provider_id', '=', $provider)
->get(['r.id', 'r.main_domain as main_domain_reseller'])
->toArray();
return array_merge($servers, $shared, $reseller);
}
} }