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 @@
Servers home + @if(count($all_servers) >= 2)
@@ -28,7 +29,7 @@
Server2
+
Hostname
+ value="{{ $server_data->hostname }}"> @error('name') {{ $message }} @enderror
@@ -40,7 +42,7 @@
- {{$server[0]->os_id}} + {{$server_data->os_id}}
@@ -50,7 +52,7 @@ NS1 ns1 255 - {{ $server[0]->ns1 }} + {{ $server_data->ns1 }}
@@ -58,7 +60,7 @@ NS2 ns2 255 - {{ $server[0]->ns2 }} + {{ $server_data->ns2 }}
@@ -67,18 +69,18 @@
Virt
@@ -90,7 +92,7 @@ 22 999999 1 - {{ $server[0]->ssh }} + {{ $server_data->ssh }}
@@ -100,28 +102,28 @@ 1000 99999 1 - {{ $server[0]->bandwidth }} + {{ $server_data->bandwidth }}
Promo price was_promo - {{ $server[0]->was_promo }} + {{ $server_data->was_promo }}
- {{$server[0]->provider_id}} + {{$server_data->provider_id}}
Price price - {{$server[0]->price}} + {{$server_data->price->price}} 9999 0.01 @@ -129,12 +131,12 @@
- {{$server[0]->term}} + {{$server_data->price->term}}
- {{$server[0]->currency}} + {{$server_data->price->currency}}
@@ -144,7 +146,7 @@ CPU cpu - {{$server[0]->cpu}} + {{$server_data->cpu}} 64 1 @@ -153,7 +155,7 @@ Ram ram - {{$server[0]->ram}} + {{$server_data->ram}} 100000 @@ -161,14 +163,14 @@ Ram type ram_type - {{$server[0]->ram_type}} + {{$server_data->ram_type}}
Disk disk - {{$server[0]->disk}} + {{$server_data->disk}} 99999 0.1 @@ -177,28 +179,34 @@ Disk type disk_type - {{$server[0]->disk_type}} + {{$server_data->disk_type}}
- {{$server[0]->location_id}} + {{$server_data->location_id}}
Owned since owned_since - {{$server[0]->owned_since }} + {{$server_data->owned_since }}
Next due date next_due_date - {{$server[0]->next_due_date }} + + @if(isset($server_data->price->next_due_date)) + {{$server_data->price->next_due_date}} + @else + {{\Carbon\Carbon::now()->addMonth(1)->format('Y-m-d')}} + @endif +
@@ -207,8 +215,8 @@ label label1 - @if(isset($labels[0]->id)) - {{$labels[0]->id}} + @if(isset($server_data->labels[0]->label->id)) + {{$server_data->labels[0]->label->id}} @endif @@ -216,8 +224,8 @@ label label2 - @if(isset($labels[1]->id)) - {{$labels[1]->id}} + @if(isset($server_data->labels[1]->label->id)) + {{$server_data->labels[1]->label->id}} @endif @@ -225,8 +233,8 @@ label label3 - @if(isset($labels[2]->id)) - {{$labels[2]->id}} + @if(isset($server_data->labels[2]->label->id)) + {{$server_data->labels[2]->label->id}} @endif @@ -234,14 +242,14 @@ label label4 - @if(isset($labels[3]->id)) - {{$labels[3]->id}} + @if(isset($server_data->labels[3]->label->id)) + {{$server_data->labels[3]->label->id}} @endif
- @foreach($ip_addresses as $ip) + @foreach($server_data->ips as $ip)
IP @@ -256,7 +264,7 @@
active === 1) ? 'checked' : '' }}> + value="1" {{ ($server_data->active === 1) ? 'checked' : '' }}> @@ -265,7 +273,7 @@
show_public === 1) ? 'checked' : '' }}> + value="1" {{ ($server_data->show_public === 1) ? 'checked' : '' }}>
+
+ diff --git a/resources/views/yabs/index.blade.php b/resources/views/yabs/index.blade.php index f18a090..aa284cc 100644 --- a/resources/views/yabs/index.blade.php +++ b/resources/views/yabs/index.blade.php @@ -14,6 +14,7 @@ Add YABs + Compare YABs
@@ -40,7 +41,7 @@ @if(!empty($yabs)) @foreach($yabs as $yab) - {{ $yab->hostname }} + {{ $yab->server->hostname }} {{ $yab->cpu_cores }} {{ $yab->cpu_freq }}Mhz {{ $yab->ram }}{{ $yab->ram_type }} @@ -53,10 +54,10 @@ No @endif - {{ $yab->d_4k }}{{ $yab->d_4k_type }} - {{ $yab->d_64k }}{{ $yab->d_64k_type }} - {{ $yab->d_512k }}{{ $yab->d_512k_type }} - {{ $yab->d_1m }}{{ $yab->d_1m_type }} + {{ $yab->disk_speed->d_4k }}{{ $yab->disk_speed->d_4k_type }} + {{ $yab->disk_speed->d_64k }}{{ $yab->disk_speed->d_64k_type }} + {{ $yab->disk_speed->d_512k }}{{ $yab->disk_speed->d_512k_type }} + {{ $yab->disk_speed->d_1m }}{{ $yab->disk_speed->d_1m_type }} {{ date_format(new DateTime($yab->output_date), 'Y-m-d g:i a') }}
@@ -66,7 +67,7 @@ + id="btn-{{$yab->server->hostname}}" title="{{$yab->id}}">
diff --git a/resources/views/yabs/show.blade.php b/resources/views/yabs/show.blade.php index cff5421..35f8475 100644 --- a/resources/views/yabs/show.blade.php +++ b/resources/views/yabs/show.blade.php @@ -16,7 +16,7 @@ Server - {{ $yab[0]->hostname }} + {{ $yab[0]->server->hostname }} CPU @@ -75,10 +75,10 @@ class="text-decoration-none">{{ $yab[0]->gb5_multi }} - Tested + Test ran @if(!is_null($yab[0]->output_date)) - {{date_format(new DateTime($yab[0]->output_date), 'jS F Y')}} + {{date_format(new DateTime($yab[0]->output_date), 'g:ia D jS F Y')}} @endif @@ -93,25 +93,25 @@ Disk speeds: - 4k {{$yab[0]->d_4k}} - {{$yab[0]->d_4k_type}} + 4k {{$yab[0]->disk_speed->d_4k}} + {{$yab[0]->disk_speed->d_4k_type}} - 64k {{$yab[0]->d_64k}} - {{$yab[0]->d_64k_type}} + 64k {{$yab[0]->disk_speed->d_64k}} + {{$yab[0]->disk_speed->d_64k_type}} - 512k {{$yab[0]->d_512k}} + 512k {{$yab[0]->disk_speed->d_512k}} {{$yab[0]->d_512k_type}} - 1m {{$yab[0]->d_1m}} {{$yab[0]->d_1m_type}} + 1m {{$yab[0]->disk_speed->d_1m}} {{$yab[0]->disk_speed->d_1m_type}} Network speed (location|send|receive): - @foreach($network as $speed_test) + @foreach($yab[0]->network_speed as $speed_test) {{$speed_test->location}} {{$speed_test->send}} diff --git a/routes/web.php b/routes/web.php index db71eaa..60697fe 100644 --- a/routes/web.php +++ b/routes/web.php @@ -70,6 +70,10 @@ Route::resource('shared', SharedController::class)->middleware(['auth']); Route::resource('yabs', YabsController::class)->middleware(['auth']); +Route::get('yabs-compare-choose', 'App\Http\Controllers\YabsController@chooseYabsCompare')->middleware(['auth'])->name('yabs.compare-choose'); + +Route::get('yabs-compare/{yabs1}/{yabs2}', 'App\Http\Controllers\YabsController@compareYabs')->middleware(['auth'])->name('yabs.compare'); + Route::get('servers-compare-choose', 'App\Http\Controllers\ServerController@chooseCompare')->middleware(['auth'])->name('servers-compare-choose'); -Route::get('servers-compare/{server1}/{server2}', 'App\Http\Controllers\ServerController@compareServers')->middleware(['auth']); +Route::get('servers-compare/{server1}/{server2}', 'App\Http\Controllers\ServerController@compareServers')->middleware(['auth'])->name('servers.compare');