From 83799b1dcbbdcbb1b4a9b33adb34b1a1e97e426a Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 25 Jan 2018 13:13:55 +0200 Subject: [PATCH] Handle migrations run before setup --- app/Http/Controllers/AppController.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/AppController.php b/app/Http/Controllers/AppController.php index b32e902632e4..f095ce9d1080 100644 --- a/app/Http/Controllers/AppController.php +++ b/app/Http/Controllers/AppController.php @@ -122,22 +122,24 @@ class AppController extends BaseController fwrite($fp, $config); fclose($fp); - if (Utils::isDatabaseSetup()) { - return Redirect::to('/login'); + if (! Utils::isDatabaseSetup()) { + // == DB Migrate & Seed == // + $sqlFile = base_path() . '/database/setup.sql'; + DB::unprepared(file_get_contents($sqlFile)); } - // == DB Migrate & Seed == // - $sqlFile = base_path() . '/database/setup.sql'; - DB::unprepared(file_get_contents($sqlFile)); Cache::flush(); + Artisan::call('db:seed', ['--force' => true, '--class' => 'UpdateSeeder']); Artisan::call('optimize', ['--force' => true]); - $firstName = trim(Input::get('first_name')); - $lastName = trim(Input::get('last_name')); - $email = trim(strtolower(Input::get('email'))); - $password = trim(Input::get('password')); - $account = $this->accountRepo->create($firstName, $lastName, $email, $password); - $user = $account->users()->first(); + if (! Account::count()) { + $firstName = trim(Input::get('first_name')); + $lastName = trim(Input::get('last_name')); + $email = trim(strtolower(Input::get('email'))); + $password = trim(Input::get('password')); + $account = $this->accountRepo->create($firstName, $lastName, $email, $password); + $user = $account->users()->first(); + } return Redirect::to('/login'); }