Added a CLI configurer and extracted configuration function from Install controllers

This commit is contained in:
Carvallegro
2017-12-31 05:21:10 +11:00
parent 183f83e1d2
commit ec5070e45f
6 changed files with 656 additions and 379 deletions

View File

@ -2,14 +2,9 @@
namespace App\Http\Controllers\Install;
use Artisan;
use App\Http\Requests\Install\Setting as Request;
use App\Models\Auth\User;
use App\Models\Company\Company;
use DotenvEditor;
use File;
use App\Utilities\AppConfigurer;
use Illuminate\Routing\Controller;
use Setting;
class Settings extends Controller
{
@ -33,76 +28,21 @@ class Settings extends Controller
public function store(Request $request)
{
// Create company
$this->createCompany($request);
$companyName = $request['company_name'];
$companyEmail= $request['company_email'];
$locale= session('locale');
AppConfigurer::createCompany($companyName, $companyEmail, $locale);
// Create user
$this->createUser($request);
$adminEmail = $request['user_email'];
$adminPassword = $request['user_password'];
$locale= session('locale');
AppConfigurer::createUser($adminEmail, $adminPassword, $locale);
// Make the final touches
$this->finalTouches();
AppConfigurer::finalTouches();
// Redirect to dashboard
return redirect('auth/login');
}
private function createCompany($request)
{
// Create company
$company = Company::create([
'domain' => '',
]);
// Set settings
Setting::set([
'general.company_name' => $request['company_name'],
'general.company_email' => $request['company_email'],
'general.default_currency' => 'USD',
'general.default_locale' => session('locale'),
]);
Setting::setExtraColumns(['company_id' => $company->id]);
Setting::save();
}
private function createUser($request)
{
// Create the user
$user = User::create([
'name' => $request[''],
'email' => $request['user_email'],
'password' => $request['user_password'],
'locale' => session('locale'),
]);
// Attach admin role
$user->roles()->attach('1');
// Attach company
$user->companies()->attach('1');
}
private function finalTouches()
{
// Caching the config and route
//Artisan::call('config:cache');
//Artisan::call('route:cache');
// Update .env file
DotenvEditor::setKeys([
[
'key' => 'APP_INSTALLED',
'value' => 'true',
],
[
'key' => 'APP_DEBUG',
'value' => 'false',
],
])->save();
// Rename the robots.txt file
try {
File::move(base_path('robots.txt.dist'), base_path('robots.txt'));
} catch (\Exception $e) {
// nothing to do
}
}
}