From 0720bfe62f4fad89158b00f0fecab3111b92e365 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 10 Feb 2017 17:03:58 -0500 Subject: [PATCH] Cleanup database query code. --- app/Http/Controllers/Admin/DatabaseController.php | 5 +---- resources/views/admin/databases/index.blade.php | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Admin/DatabaseController.php b/app/Http/Controllers/Admin/DatabaseController.php index 6cfa73041..1b7dcb5a2 100644 --- a/app/Http/Controllers/Admin/DatabaseController.php +++ b/app/Http/Controllers/Admin/DatabaseController.php @@ -48,10 +48,7 @@ class DatabaseController extends Controller { return view('admin.databases.index', [ 'databases' => Models\Database::with('server')->paginate(50), - 'hosts' => Models\DatabaseServer::select( - 'database_servers.*', - DB::raw('(SELECT COUNT(*) FROM `databases` WHERE `databases`.`db_server` = database_servers.id) as c_databases') - )->with('node')->paginate(20), + 'hosts' => Models\DatabaseServer::withCount('databases')->with('node')->paginate(20), ]); } diff --git a/resources/views/admin/databases/index.blade.php b/resources/views/admin/databases/index.blade.php index bb7be1e3f..f1c2a4aac 100644 --- a/resources/views/admin/databases/index.blade.php +++ b/resources/views/admin/databases/index.blade.php @@ -92,7 +92,7 @@ {{ $database->name }} {{ $database->host }}:{{ $database->port }} {{ $database->username }} - {{ $database->c_databases }} + {{ $database->databases_count }} @if(is_null($database->node))unlinked@else{{ $database->node->name }}@endif