From 415b60a293dfafb1024cc591c01e72c26b4de1a6 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 14 May 2016 16:09:00 -0700 Subject: [PATCH] Added check for setup in Setting model --- app/Http/Kernel.php | 1 - app/Http/Middleware/CheckForSetup.php | 24 +++++++++--------------- app/Models/Setting.php | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 9d2a1229d7..6ae3870c11 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -34,7 +34,6 @@ class Kernel extends HttpKernel \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \App\Http\Middleware\VerifyCsrfToken::class, \App\Http\Middleware\CheckLocale::class, - \App\Http\Middleware\CheckForSetup::class, ], 'api' => [ diff --git a/app/Http/Middleware/CheckForSetup.php b/app/Http/Middleware/CheckForSetup.php index 03319cd110..f2bef6bb88 100644 --- a/app/Http/Middleware/CheckForSetup.php +++ b/app/Http/Middleware/CheckForSetup.php @@ -7,36 +7,30 @@ use Config; use Route; use Schema; use App\Models\User; +use App\Models\Setting; class CheckForSetup { public function handle($request, Closure $next, $guard = null) { - try { + if (Setting::setupCompleted()) { - $users_table_exists = Schema::hasTable('users'); - $settings_table_exists = Schema::hasTable('settings'); - - if ($users_table_exists && $settings_table_exists) { - $usercount = User::withTrashed()->count(); - if (($usercount > 0) && (Route::is('setup*'))) { + if ($request->is('setup*')) { return redirect(config('app.url')); } else { return $next($request); } + } else { + if (!$request->is('setup*')) { + return redirect(config('app.url').'/setup')->with('Request',$request); + } + return $next($request); + } - } catch (\Exception $e) { - return $next($request); - } - - - - - } } diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 6f5bd75c65..51ce6e809b 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use Watson\Validating\ValidatingTrait; +use Schema; class Setting extends Model { @@ -40,6 +41,28 @@ class Setting extends Model return $static_cache; } + public static function setupCompleted() { + + $users_table_exists = Schema::hasTable('users'); + $settings_table_exists = Schema::hasTable('settings'); + + + if ($users_table_exists && $settings_table_exists) { + $usercount = User::withTrashed()->count(); + + if ($usercount > 0) { + return true; + } + return false; + } else { + return false; + } + return false; + + + + } + public function lar_ver() { $app = \App::getFacadeApplication();