diff --git a/README.md b/README.md index 36625f5..017167b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Despite what the name infers this self hosted web app isn't just for storing idl a [YABs](https://github.com/masonr/yet-another-bench-script) output you can get disk & network speed values along with GeekBench 5 scores to do easier comparing and sorting. -[![Generic badge](https://img.shields.io/badge/version-2.1.1-blue.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/Laravel-9.0-red.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/PHP-8.1-purple.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/Bootstrap-5.1-pink.svg)](https://shields.io/) +[![Generic badge](https://img.shields.io/badge/version-2.1.2-blue.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/Laravel-9.0-red.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/PHP-8.1-purple.svg)](https://shields.io/) [![Generic badge](https://img.shields.io/badge/Bootstrap-5.1-pink.svg)](https://shields.io/) @@ -19,12 +19,17 @@ GeekBench 5 scores to do easier comparing and sorting. [Cloud Five Limited](https://cloud-v.net/) for providing the hosting for demo installation. -## 2.1.1 changes (19th June 2022): +## 2.1.2 changes (19th July 2022): -* Added compatability for YABs version v2022-06-11 -* Added Create, Update and Delete servers with API -* Added Update pricing with API -* Updated YABs compatible versions check +* Added YABs compare page +* Added caching for YABs +* Added LabelsAssigned model +* Updated Server model to use relationships +* Updated Shared model to use relationships +* Updated Shared model to use caching +* Updated Table model to have table name defined +* Fixed server compare initial selection +* Fixed switch in getIpForDomain() ## Requires diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index 53662a0..19015fa 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -309,6 +309,7 @@ class ApiController extends Controller if (isset($data['0']['ip'])) { return response(array('ip' => $data['0']['ip']), 200); } + break; case "AAAA": $data = dns_get_record($domainname, DNS_AAAA); if (isset($data['0']['ipv6'])) { diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index b86a182..5185081 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -19,9 +19,9 @@ class ServerController extends Controller public function index() { - $servers = Server::activeServersDataIndexPage(); + $servers = Server::allActiveServers(); - $non_active_servers = Server::nonActiveServersDataIndexPage(); + $non_active_servers = Server::allNonActiveServers(); return view('servers.index', compact(['servers', 'non_active_servers'])); } @@ -41,7 +41,7 @@ class ServerController extends Controller Session::save(); if ((Session::get('show_servers_public') === 1)) { - $servers = Server::publicServerData(); + $servers = Server::allPublicServers(); return view('servers.public-index', compact('servers')); } return response()->view('errors.404', array("status" => 404, "title" => "Page not found", "message" => ""), 404); @@ -121,24 +121,16 @@ class ServerController extends Controller public function show(Server $server) { - $server_extras = Server::serverDataShowPage($server->id); + $server_data = Server::server($server->id)[0]; - $network_speeds = Yabs::networkSpeedsForServer($server->id); - - $ip_addresses = IPs::ipsForServer($server->id); - - $labels = Labels::labelsForService($server->id); - - return view('servers.show', compact(['server', 'server_extras', 'network_speeds', 'labels', 'ip_addresses'])); + return view('servers.show', compact(['server_data'])); } public function edit(Server $server) { - $ip_addresses = IPs::ipsForServer($server->id); + $server_data = Server::server($server->id)[0]; - $server = Pricing::pricingForService($server->id); - - return view('servers.edit', compact(['server', 'ip_addresses'])); + return view('servers.edit', compact(['server_data'])); } public function update(Request $request, Server $server) @@ -229,28 +221,24 @@ class ServerController extends Controller } public function chooseCompare() - { + {//NOTICE: Selecting servers is not cached yet $all_servers = Server::where('has_yabs', 1)->get(); return view('servers.choose-compare', compact('all_servers')); } public function compareServers($server1, $server2) { - $server1_data = Server::serverCompareData($server1); + $server1_data = Server::server($server1); - if (count($server1_data) === 0) { + if (!isset($server1_data[0]->yabs[0])) { return response()->view('errors.404', array("status" => 404, "title" => "Page not found", "message" => "No server with YABs data was found for id '$server1'"), 404); } - $server1_network = Yabs::serverCompareNetwork($server1_data[0]->yabs_id); + $server2_data = Server::server($server2); - $server2_data = Server::serverCompareData($server2); - - if (count($server2_data) === 0) { + if (!isset($server2_data[0]->yabs[0])) { return response()->view('errors.404', array("status" => 404, "title" => "Page not found", "message" => "No server with YABs data was found for id '$server2'"), 404); } - - $server2_network = Yabs::serverCompareNetwork($server2_data[0]->yabs_id); - return view('servers.compare', compact('server1_data', 'server2_data', 'server1_network', 'server2_network')); + return view('servers.compare', compact('server1_data', 'server2_data')); } } diff --git a/app/Http/Controllers/SharedController.php b/app/Http/Controllers/SharedController.php index e6fd36d..0a3f26e 100644 --- a/app/Http/Controllers/SharedController.php +++ b/app/Http/Controllers/SharedController.php @@ -16,8 +16,7 @@ class SharedController extends Controller { public function index() { - $shared = Shared::sharedDataIndexPage(); - + $shared = Shared::allSharedHosting(); return view('shared.index', compact(['shared'])); } @@ -28,7 +27,6 @@ class SharedController extends Controller public function store(Request $request) { - $request->validate([ 'domain' => 'required|min:4', 'shared_type' => 'required', @@ -54,17 +52,13 @@ class SharedController extends Controller $shared_id = Str::random(8); $pricing = new Pricing(); - $as_usd = $pricing->convertToUSD($request->price, $request->currency); - $pricing->insertPricing(2, $shared_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date); Labels::deleteLabelsAssignedTo($shared_id); - Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $shared_id); IPs::deleteIPsAssignedTo($shared_id); - if (!is_null($request->dedicated_ip)) { IPs::insertIP($shared_id, $request->dedicated_ip); } @@ -88,6 +82,7 @@ class SharedController extends Controller 'db__limit' => $request->db ]); + Cache::forget('all_shared'); Home::homePageCacheForget(); return redirect()->route('shared.index') @@ -96,24 +91,14 @@ class SharedController extends Controller public function show(Shared $shared) { - $shared_extras = Shared::sharedDataShowPage($shared->id); - - $labels = Labels::labelsForService($shared->id); - - $ip_address = IPs::ipsForServer($shared->id); - - return view('shared.show', compact(['shared', 'shared_extras', 'labels', 'ip_address'])); + $shared = Shared::sharedHosting($shared->id)[0]; + return view('shared.show', compact(['shared'])); } public function edit(Shared $shared) { - $labels = Labels::labelsForService($shared->id); - - $ip_address = IPs::ipsForServer($shared->id); - - $shared = Shared::sharedEditDataPage($shared->id); - - return view('shared.edit', compact(['shared', 'labels', 'ip_address'])); + $shared = Shared::sharedHosting($shared->id); + return view('shared.edit', compact(['shared'])); } public function update(Request $request, Shared $shared) @@ -161,23 +146,20 @@ class SharedController extends Controller ]); $pricing = new Pricing(); - $as_usd = $pricing->convertToUSD($request->price, $request->currency); - $pricing->updatePricing($request->id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date); Labels::deleteLabelsAssignedTo($request->id); - Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $request->id); - Cache::forget("labels_for_service.{$request->id}"); IPs::deleteIPsAssignedTo($request->id); - if (isset($request->dedicated_ip)) { IPs::insertIP($request->id, $request->dedicated_ip); } + Cache::forget("shared_hosting.{$request->id}"); + Cache::forget('all_shared'); Home::homePageCacheForget(); return redirect()->route('shared.index') @@ -188,7 +170,6 @@ class SharedController extends Controller { $shared_id = $shared->id; $items = Shared::find($shared_id); - $items->delete(); $p = new Pricing(); @@ -198,6 +179,8 @@ class SharedController extends Controller IPs::deleteIPsAssignedTo($shared_id); + Cache::forget("shared_hosting.$shared_id"); + Cache::forget('all_shared'); Home::homePageCacheForget(); return redirect()->route('shared.index') diff --git a/app/Http/Controllers/YabsController.php b/app/Http/Controllers/YabsController.php index 1eab347..5658589 100644 --- a/app/Http/Controllers/YabsController.php +++ b/app/Http/Controllers/YabsController.php @@ -16,11 +16,7 @@ class YabsController extends Controller { public function index() { - $yabs = DB::table('yabs as y') - ->join('servers as s', 'y.server_id', '=', 's.id') - ->Join('disk_speed as ds', 'y.id', '=', 'ds.id') - ->get(['y.*', 's.hostname', 'ds.*']); - + $yabs = Yabs::allYabs(); return view('yabs.index', compact(['yabs'])); } @@ -38,7 +34,6 @@ class YabsController extends Controller if (isset($yabs['error_id'])) { return back()->withErrors(["yabs" => 'Problem inserting YABs. Error id ' . $yabs['error_id']])->withInput(); - //return redirect()->route('yabs.index')->with('error', 'Problem inserting YABs. Error id ' . $yabs['error_id']); } //No errors, do insert @@ -111,6 +106,7 @@ class YabsController extends Controller Cache::forget('all_active_servers');//all servers cache Cache::forget('non_active_servers');//all servers cache + Cache::forget('all_yabs');//Forget the all YABs cache return redirect()->route('yabs.index') ->with('success', 'Success inserting YABs'); @@ -118,17 +114,8 @@ class YabsController extends Controller public function show(Yabs $yab) { - $yab = DB::table('yabs as y') - ->join('servers as s', 'y.server_id', '=', 's.id') - ->join('disk_speed as ds', 'y.id', '=', 'ds.id') - ->where('y.id', '=', $yab->id) - ->get(['y.*', 's.hostname', 'ds.*']); - - $network = DB::table('network_speed') - ->where('id', '=', $yab[0]->id) - ->get(); - - return view('yabs.show', compact(['yab', 'network'])); + $yab = Yabs::yabs($yab->id); + return view('yabs.show', compact(['yab'])); } public function destroy(Yabs $yab) @@ -136,11 +123,40 @@ class YabsController extends Controller $yabs = Yabs::find($yab->id); $yabs->delete(); - $update_server = DB::table('servers') - ->where('id', $yab->server_id) - ->update(['has_yabs' => 0]); + if (Server::serverYabsAmount($yab->server_id) === 0) { + DB::table('servers') + ->where('id', $yab->server_id) + ->update(['has_yabs' => 0]); + } + + Cache::forget('all_yabs'); + Cache::forget("yabs.{$yab->id}"); return redirect()->route('yabs.index') ->with('success', 'YABs was deleted Successfully.'); } + + public function chooseYabsCompare() + { + $all_yabs = Yabs::allYabs(); + return view('yabs.choose-compare', compact('all_yabs')); + } + + public function compareYabs($yabs1, $yabs2) + { + $yabs1_data = Yabs::yabs($yabs1); + + if (count($yabs1_data) === 0) { + return response()->view('errors.404', array("status" => 404, "title" => "Page not found", "message" => "No YABs data was found for id '$yabs1'"), 404); + } + + $yabs2_data = Yabs::yabs($yabs2); + + if (count($yabs2_data) === 0) { + return response()->view('errors.404', array("status" => 404, "title" => "Page not found", "message" => "No YABs data was found for id '$server2'"), 404); + } + + return view('yabs.compare', compact('yabs1_data', 'yabs2_data')); + } + } diff --git a/app/Models/DiskSpeed.php b/app/Models/DiskSpeed.php index eb434d2..1094c5a 100644 --- a/app/Models/DiskSpeed.php +++ b/app/Models/DiskSpeed.php @@ -9,7 +9,14 @@ class DiskSpeed extends Model { use HasFactory; + public $incrementing = false; + protected $table = 'disk_speed'; protected $fillable = ['id', 'server_id', 'd_4k', 'd_4k_type', 'd_4k_as_mbps', 'd_64k', 'd_64k_type', 'd_64k_as_mbps', 'd_512k', 'd_512k_type', 'd_512k_as_mbps', 'd_1m', 'd_1m_type', 'd_1m_as_mbps']; + + public function yabs() + { + return $this->belongsTo(Yabs::class, 'id', 'id'); + } } diff --git a/app/Models/Labels.php b/app/Models/Labels.php index 8c7a2fc..50f1840 100644 --- a/app/Models/Labels.php +++ b/app/Models/Labels.php @@ -13,6 +13,8 @@ class Labels extends Model public $incrementing = false; + protected $table = 'labels'; + protected $fillable = ['id', 'label', 'server_id', 'server_id_2', 'domain_id', 'domain_id_2', 'shared_id', 'shared_id_2']; public static function deleteLabelsAssignedTo($service_id) diff --git a/app/Models/LabelsAssigned.php b/app/Models/LabelsAssigned.php new file mode 100644 index 0000000..d1e4b1d --- /dev/null +++ b/app/Models/LabelsAssigned.php @@ -0,0 +1,23 @@ +hasOne(Labels::class, 'id', 'label_id'); + } + +} diff --git a/app/Models/NetworkSpeed.php b/app/Models/NetworkSpeed.php index 39f5b9e..9879517 100644 --- a/app/Models/NetworkSpeed.php +++ b/app/Models/NetworkSpeed.php @@ -9,7 +9,14 @@ class NetworkSpeed extends Model { use HasFactory; + public $incrementing = false; + protected $table = 'network_speed'; protected $fillable = ['id', 'server_id', 'location', 'send', 'send_type', 'send_as_mbps', 'receive', 'receive_type', 'receive_as_mbps', 'created_at', 'updated_at']; + + public function yabs() + { + return $this->belongsTo(Yabs::class, 'id', 'id'); + } } diff --git a/app/Models/Pricing.php b/app/Models/Pricing.php index b5af33d..31f578c 100644 --- a/app/Models/Pricing.php +++ b/app/Models/Pricing.php @@ -141,13 +141,4 @@ class Pricing extends Model }); } - public static function pricingForService(string $service_id) - { - return Cache::remember("service_pricing.$service_id", now()->addWeek(1), function () use ($service_id) { - return DB::table('servers as s') - ->join('pricings as p', 's.id', '=', 'p.service_id') - ->where('s.id', '=', $service_id) - ->get(['s.*', 'p.*']); - }); - } } diff --git a/app/Models/Server.php b/app/Models/Server.php index 40396e3..4bfd330 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Process; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Cache; @@ -21,6 +22,48 @@ class Server extends Model */ private $id; + public static function allServers() + {//All servers and relationships (no using joins) + return Cache::remember("all_servers", now()->addMonth(1), function () { + return Server::with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'labels.label'])->get(); + }); + } + + public static function server(string $server_id) + {//Single server and relationships (no using joins) + return Cache::remember("server.$server_id", now()->addMonth(1), function () use ($server_id) { + return Server::where('id', $server_id) + ->with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'labels.label'])->get(); + }); + } + + public static function allActiveServers() + {//All ACTIVE servers and relationships replaces activeServersDataIndexPage() + return Cache::remember("all_active_servers", now()->addMonth(1), function () { + return Server::where('active', '=', 1) + ->with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'labels.label']) + ->get(); + }); + } + + public static function allNonActiveServers() + {//All NON ACTIVE servers and relationships replaces nonActiveServersDataIndexPage() + return Cache::remember("non_active_servers", now()->addMonth(1), function () { + return Server::where('active', '=', 0) + ->with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'labels.label']) + ->get(); + }); + } + + public static function allPublicServers() + {//server data that will be publicly viewable (values in settings) + return Cache::remember("public_server_data", now()->addMonth(1), function () { + return Server::where('show_public', '=', 1) + ->with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'labels.label']) + ->get(); + }); + } + public static function serviceServerType($type) { if ($type === 1) { @@ -158,11 +201,12 @@ class Server extends Model public static function serverRelatedCacheForget(): void { + Cache::forget('all_servers');//All servers Cache::forget('services_count');//Main page services_count cache Cache::forget('due_soon');//Main page due_soon cache Cache::forget('recently_added');//Main page recently_added cache - Cache::forget('all_active_servers');//all servers cache - Cache::forget('non_active_servers');//all servers cache + Cache::forget('all_active_servers');//all active servers cache + Cache::forget('non_active_servers');//all non active servers cache Cache::forget('servers_summary');//servers summary cache Cache::forget('public_server_data');//public servers Cache::forget('all_pricing');//All pricing @@ -172,81 +216,50 @@ class Server extends Model public static function serverSpecificCacheForget(string $server_id): void { - Cache::forget("server_show_data.$server_id");//data for show - Cache::forget("ip_addresses.$server_id");//ips for server - Cache::forget("labels_for_service.$server_id");//labels for server + Cache::forget("server.$server_id");//Will replace one below Cache::forget("service_pricing.$server_id");//Pricing } - public static function activeServersDataIndexPage() - { - return Cache::remember('all_active_servers', now()->addMonth(1), function () { - return DB::table('servers as s') - ->join('pricings as pr', 's.id', '=', 'pr.service_id') - ->join('providers as p', 's.provider_id', '=', 'p.id') - ->join('locations as l', 's.location_id', '=', 'l.id') - ->join('os as o', 's.os_id', '=', 'o.id') - ->where('s.active', '=', 1) - ->get(['s.*', 'pr.currency', 'pr.price', 'pr.term', 'pr.as_usd', 'pr.next_due_date', 'p.name as provider_name', 'l.name as location', 'o.name as os_name']); - }); + public static function serverYabsAmount(string $server_id): int + {//Returns amount of YABs a server has + return DB::table('yabs') + ->where('server_id', '=', $server_id) + ->get()->count(); } - public static function nonActiveServersDataIndexPage() + public function yabs() { - return Cache::remember('non_active_servers', now()->addMonth(1), function () { - return DB::table('servers as s') - ->join('pricings as pr', 's.id', '=', 'pr.service_id') - ->join('providers as p', 's.provider_id', '=', 'p.id') - ->join('locations as l', 's.location_id', '=', 'l.id') - ->join('os as o', 's.os_id', '=', 'o.id') - ->where('s.active', '=', 0) - ->get(['s.*', 'pr.currency', 'pr.price', 'pr.term', 'pr.as_usd', 'p.name as provider_name', 'l.name as location', 'o.name as os_name']); - }); + return $this->hasMany(Yabs::class, 'server_id', 'id'); } - public static function serverDataShowPage(string $server_id) + public function ips() { - return Cache::remember("server_show_data.$server_id", now()->addDay(1), function () use ($server_id) { - return DB::table('servers as s') - ->join('pricings as pr', 's.id', '=', 'pr.service_id') - ->join('providers as p', 's.provider_id', '=', 'p.id') - ->join('locations as l', 's.location_id', '=', 'l.id') - ->join('os as o', 's.os_id', '=', 'o.id') - ->Leftjoin('yabs as y', 's.id', '=', 'y.server_id') - ->Leftjoin('disk_speed as ds', 'y.id', '=', 'ds.id') - ->where('s.id', '=', $server_id) - ->get(['s.*', 'p.name as provider', 'l.name as location', 'o.name as os_name', 'pr.*', 'y.*', 'ds.*']); - }); + return $this->hasMany(IPs::class, 'service_id', 'id'); } - public static function publicServerData() + public function location() { - return Cache::remember('public_server_data', now()->addMonth(1), function () { - return DB::table('servers as s') - ->Join('pricings as pr', 's.id', '=', 'pr.service_id') - ->Join('providers as p', 's.provider_id', '=', 'p.id') - ->Join('locations as l', 's.location_id', '=', 'l.id') - ->Join('os as o', 's.os_id', '=', 'o.id') - ->LeftJoin('ips as i', 's.id', '=', 'i.service_id') - ->LeftJoin('yabs as y', 's.id', '=', 'y.server_id') - ->LeftJoin('disk_speed as ds', 'y.id', '=', 'ds.id') - ->where('s.show_public', '=', 1) - ->get(['pr.currency', 'pr.price', 'pr.term', 'pr.as_usd', 'pr.next_due_date', 'pr.service_id', 'p.name as provider_name', 'l.name as location', 'o.name as os_name', 'y.*', 'y.id as yabs_id', 'ds.*', 's.*', 'i.address as ip', 'i.is_ipv4']); - }); + return $this->hasOne(Locations::class, 'id', 'location_id'); } - public static function serverCompareData(string $server_id) + public function provider() { - return Cache::remember("server_compare.$server_id", now()->addMonth(1), function () use ($server_id) { - return DB::table('servers as s') - ->join('pricings as pr', 's.id', '=', 'pr.service_id') - ->join('providers as p', 's.provider_id', '=', 'p.id') - ->join('locations as l', 's.location_id', '=', 'l.id') - ->Join('yabs as y', 's.id', '=', 'y.server_id') - ->Join('disk_speed as ds', 'y.id', '=', 'ds.id') - ->where('s.id', '=', $server_id) - ->get(['s.*', 'p.name as provider_name', 'l.name as location', 'pr.*', 'y.*', 'y.id as yabs_id', 'ds.*']); - }); + return $this->hasOne(Providers::class, 'id', 'provider_id'); + } + + public function os() + { + return $this->hasOne(OS::class, 'id', 'os_id'); + } + + public function price() + { + return $this->hasOne(Pricing::class, 'service_id', 'id'); + } + + public function labels() + { + return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); } } diff --git a/app/Models/Shared.php b/app/Models/Shared.php index 267244d..1cac7c1 100644 --- a/app/Models/Shared.php +++ b/app/Models/Shared.php @@ -17,30 +17,44 @@ class Shared extends Model public $incrementing = false; - public static function sharedDataIndexPage() - { - return DB::table('shared_hosting as s') - ->join('providers as p', 's.provider_id', '=', 'p.id') - ->join('locations as l', 's.location_id', '=', 'l.id') - ->join('pricings as pr', 's.id', '=', 'pr.service_id') - ->get(['s.*', 'p.name as provider_name', 'pr.*', 'l.name as location']); + public static function allSharedHosting() + {//All shared hosting and relationships (no using joins) + return Cache::remember("all_shared", now()->addMonth(1), function () { + return Shared::with(['location', 'provider', 'price', 'ips', 'labels', 'labels.label'])->get(); + }); } - public static function sharedDataShowPage(string $shared_id) - { - return DB::table('shared_hosting as s') - ->join('pricings as pr', 's.id', '=', 'pr.service_id') - ->join('providers as p', 's.provider_id', '=', 'p.id') - ->join('locations as l', 's.location_id', '=', 'l.id') - ->where('s.id', '=', $shared_id) - ->get(['s.*', 'p.name as provider_name', 'l.name as location', 'pr.*']); + public static function sharedHosting(string $shared_id) + {//Single shared hosting and relationships (no using joins) + return Cache::remember("shared_hosting.$shared_id", now()->addMonth(1), function () use ($shared_id) { + return Shared::where('id', $shared_id) + ->with(['location', 'provider', 'price', 'ips', 'labels', 'labels.label'])->get(); + }); } - public static function sharedEditDataPage(string $shared_id) + public function ips() { - return DB::table('shared_hosting as s') - ->join('pricings as p', 's.id', '=', 'p.service_id') - ->where('s.id', '=', $shared_id) - ->get(['s.*', 'p.*']); + return $this->hasMany(IPs::class, 'service_id', 'id'); } + + public function location() + { + return $this->hasOne(Locations::class, 'id', 'location_id'); + } + + public function provider() + { + return $this->hasOne(Providers::class, 'id', 'provider_id'); + } + + public function price() + { + return $this->hasOne(Pricing::class, 'service_id', 'id'); + } + + public function labels() + { + return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); + } + } diff --git a/app/Models/Yabs.php b/app/Models/Yabs.php index b93186d..3010313 100644 --- a/app/Models/Yabs.php +++ b/app/Models/Yabs.php @@ -35,4 +35,35 @@ class Yabs extends Model }); } + public static function yabs(string $yabs_id) + { + return Cache::remember("yabs.$yabs_id", now()->addMonth(1), function () use ($yabs_id) { + return self::where('id', $yabs_id)->with(['server', 'disk_speed', 'network_speed']) + ->get(); + }); + } + + public static function allYabs() + { + return Cache::remember("all_yabs", now()->addMonth(1), function () { + return self::with(['server', 'disk_speed', 'network_speed']) + ->get(); + }); + } + + public function server() + { + return $this->hasOne(Server::class, 'id', 'server_id'); + } + + public function disk_speed() + { + return $this->hasOne(DiskSpeed::class, 'id', 'id'); + } + + public function network_speed() + { + return $this->hasMany(NetworkSpeed::class, 'id', 'id'); + } + } diff --git a/resources/views/servers/choose-compare.blade.php b/resources/views/servers/choose-compare.blade.php index 58665fd..82154eb 100644 --- a/resources/views/servers/choose-compare.blade.php +++ b/resources/views/servers/choose-compare.blade.php @@ -10,6 +10,7 @@
You need to have added a YABs to at least 2 servers to use this feature
+ @endif+ | {{ $yabs1_data[0]->id }} | +DIF | +{{ $yabs2_data[0]->id}} | +
---|---|---|---|
Date | +{{ date_format(new DateTime($yabs1_data[0]->output_date), 'g:ia D jS F Y') }} | ++ {{\Carbon\Carbon::parse($yabs1_data[0]->output_date)->diffForHumans(\Carbon\Carbon::parse($yabs2_data[0]->output_date))}} + | +{{ date_format(new DateTime($yabs2_data[0]->output_date), 'g:ia D jS F Y') }} | +
Server | +{{$yabs1_data[0]->server->hostname}} | ++ | {{$yabs2_data[0]->server->hostname}} | +
CPU count | +{{$yabs1_data[0]->cpu_cores}} | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->cpu_cores, $yabs2_data[0]->cpu_cores, ' cores') !!} +{{$yabs2_data[0]->cpu_cores}} | +|
CPU freq | +{{$yabs1_data[0]->cpu_freq}}Mhz | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->cpu_freq, $yabs2_data[0]->cpu_freq, 'Mhz') !!} +{{$yabs2_data[0]->cpu_freq}}Mhz | +|
Ram | +{{$yabs1_data[0]->ram_mb}}MB | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->ram_mb, $yabs2_data[0]->ram_mb, 'MB') !!} +{{$yabs2_data[0]->ram_mb}}MB | +|
Disk | +{{$yabs1_data[0]->disk_gb}}GB | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->disk_gb, $yabs2_data[0]->disk_gb, 'GB') !!} +{{$yabs2_data[0]->disk_gb}}GB | +|
GB5 single | +{{$yabs1_data[0]->gb5_single}} | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->gb5_single, $yabs2_data[0]->gb5_single, '') !!} +{{$yabs2_data[0]->gb5_single}} | +|
GB5 multi | +{{$yabs1_data[0]->gb5_multi}} | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->gb5_multi, $yabs2_data[0]->gb5_multi, '') !!} +{{$yabs2_data[0]->gb5_multi}} | +|
4k disk | +{{$yabs1_data[0]->disk_speed->d_4k_as_mbps}}MB/s + | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->disk_speed->d_4k_as_mbps, $yabs2_data[0]->disk_speed->d_4k_as_mbps, 'MB/s') !!} +{{$yabs2_data[0]->disk_speed->d_4k_as_mbps}}MB/s + | +|
64k disk | +{{$yabs1_data[0]->disk_speed->d_64k_as_mbps}}MB/s + | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->disk_speed->d_64k_as_mbps, $yabs2_data[0]->disk_speed->d_64k_as_mbps, 'MB/s') !!} +{{$yabs2_data[0]->disk_speed->d_64k_as_mbps}}MB/s + | +|
512k disk | +{{$yabs1_data[0]->disk_speed->d_512k_as_mbps}}MB/s | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->disk_speed->d_512k_as_mbps, $yabs2_data[0]->disk_speed->d_512k_as_mbps, 'MB/s') !!} +{{$yabs2_data[0]->disk_speed->d_512k_as_mbps}}MB/s | +|
1m disk | +{{$yabs1_data[0]->disk_speed->d_1m_as_mbps}}MB/s + | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->disk_speed->d_1m_as_mbps, $yabs2_data[0]->disk_speed->d_1m_as_mbps, 'MB/s') !!} +{{$yabs2_data[0]->disk_speed->d_1m_as_mbps}}MB/s + | +|
{{$yabs1_data[0]->network_speed[0]->location}} send | +{{$yabs1_data[0]->network_speed[0]->send_as_mbps}}MBps | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[0]->send_as_mbps, $yabs2_data[0]->network_speed[0]->send_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[0]->send_as_mbps}}MBps | +|
{{$yabs1_data[0]->network_speed[0]->location}} receive | +{{$yabs1_data[0]->network_speed[0]->receive_as_mbps}}MBps | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[0]->receive_as_mbps, $yabs2_data[0]->network_speed[0]->receive_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[0]->receive_as_mbps}}MBps | +|
{{$yabs1_data[0]->network_speed[1]->location}} send | +{{$yabs1_data[0]->network_speed[1]->send_as_mbps}}MBps | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[1]->send_as_mbps, $yabs2_data[0]->network_speed[1]->send_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[1]->send_as_mbps}}MBps | +|
{{$yabs1_data[0]->network_speed[1]->location}} receive | +{{$yabs1_data[0]->network_speed[1]->receive_as_mbps}}MBps + | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[1]->receive_as_mbps, $yabs2_data[0]->network_speed[1]->receive_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[1]->receive_as_mbps}}MBps + | +|
{{$yabs1_data[0]->network_speed[2]->location}} send | +{{$yabs1_data[0]->network_speed[2]->send_as_mbps}}MBps | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[2]->send_as_mbps, $yabs2_data[0]->network_speed[2]->send_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[2]->send_as_mbps}}MBps | +|
{{$yabs1_data[0]->network_speed[2]->location}} receive | +{{$yabs1_data[0]->network_speed[2]->receive_as_mbps}}MBps + | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[2]->receive_as_mbps, $yabs2_data[0]->network_speed[2]->receive_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[2]->receive_as_mbps}}MBps + | +|
{{$yabs1_data[0]->network_speed[3]->location}} send | +{{$yabs1_data[0]->network_speed[3]->send_as_mbps}}MBps | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[3]->send_as_mbps, $yabs2_data[0]->network_speed[3]->send_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[3]->send_as_mbps}}MBps | +|
{{$yabs1_data[0]->network_speed[3]->location}} receive | +{{$yabs1_data[0]->network_speed[3]->receive_as_mbps}}MBps + | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[3]->receive_as_mbps, $yabs2_data[0]->network_speed[3]->receive_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[3]->receive_as_mbps}}MBps + | +|
{{$yabs1_data[0]->network_speed[4]->location}} send | +{{$yabs1_data[0]->network_speed[4]->send_as_mbps}}MBps | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[4]->send_as_mbps, $yabs2_data[0]->network_speed[4]->send_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[4]->send_as_mbps}}MBps | +|
{{$yabs1_data[0]->network_speed[4]->location}} receive | +{{$yabs1_data[0]->network_speed[4]->receive_as_mbps}}MBps + | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[4]->receive_as_mbps, $yabs2_data[0]->network_speed[4]->receive_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[4]->receive_as_mbps}}MBps + | +|
{{$yabs1_data[0]->network_speed[4]->location}} send | +{{$yabs1_data[0]->network_speed[4]->send_as_mbps}}MBps | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[4]->send_as_mbps, $yabs2_data[0]->network_speed[5]->send_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[5]->send_as_mbps}}MBps | +|
{{$yabs1_data[0]->network_speed[4]->location}} receive | +{{$yabs1_data[0]->network_speed[4]->receive_as_mbps}}MBps + | + {!! \App\Models\Server::tableRowCompare($yabs1_data[0]->network_speed[4]->receive_as_mbps, $yabs2_data[0]->network_speed[5]->receive_as_mbps, 'MBps') !!} +{{$yabs2_data[0]->network_speed[5]->receive_as_mbps}}MBps + | +