From bdb51a27a4137095ac797e878d337070850d6dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Mon, 17 May 2021 10:57:13 +0300 Subject: [PATCH] fixed app url issue --- .env.example | 1 + .env.testing | 1 + app/Utilities/Installer.php | 22 ++++++++++++++-------- app/Utilities/Overrider.php | 6 ++++-- config/app.php | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index 016748105..ab3781400 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,7 @@ APP_INSTALLED=false APP_KEY= APP_DEBUG=true APP_SCHEDULE_TIME="09:00" +APP_URL= DB_CONNECTION=mysql DB_HOST=localhost diff --git a/.env.testing b/.env.testing index 41d3ee148..ed5cd3076 100644 --- a/.env.testing +++ b/.env.testing @@ -5,6 +5,7 @@ APP_INSTALLED=true APP_KEY=base64:xBC+BxlC7sXhYAtpTZv8TYAHqoPgsJaXL0S5Id6BbBc= APP_DEBUG=true APP_SCHEDULE_TIME="09:00" +APP_URL= DB_CONNECTION=sqlite DB_DATABASE=:memory: diff --git a/app/Utilities/Installer.php b/app/Utilities/Installer.php index 5b16691fe..a2a2f756e 100644 --- a/app/Utilities/Installer.php +++ b/app/Utilities/Installer.php @@ -5,10 +5,10 @@ namespace App\Utilities; use App\Jobs\Auth\CreateUser; use App\Jobs\Common\CreateCompany; use App\Utilities\Console; -use Artisan; -use Config; -use DB; -use File; +use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Config; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\File; use Illuminate\Support\Str; /** @@ -232,7 +232,7 @@ class Installer public static function createCompany($name, $email, $locale) { - dispatch_now(new CreateCompany([ + dispatch_sync(new CreateCompany([ 'name' => $name, 'domain' => '', 'email' => $email, @@ -244,7 +244,7 @@ class Installer public static function createUser($email, $password, $locale) { - dispatch_now(new CreateUser([ + dispatch_sync(new CreateUser([ 'name' => '', 'email' => $email, 'password' => $password, @@ -258,13 +258,19 @@ class Installer public static function finalTouches() { // Update .env file - static::updateEnv([ + $env = [ 'APP_LOCALE' => session('locale'), 'APP_INSTALLED' => 'true', 'APP_DEBUG' => 'false', 'FIREWALL_ENABLED' => 'true', 'MODEL_CACHE_ENABLED' => 'true', - ]); + ]; + + if (!app()->runningInConsole()) { + $env['APP_URL'] = request()->getUriForPath(''); + } + + static::updateEnv($env); // Rename the robots.txt file try { diff --git a/app/Utilities/Overrider.php b/app/Utilities/Overrider.php index 6622cdce7..0430b81fb 100644 --- a/app/Utilities/Overrider.php +++ b/app/Utilities/Overrider.php @@ -50,8 +50,10 @@ class Overrider app()->setLocale(setting('default.locale')); } - // Set app url dynamically - config(['app.url' => url('/')]); + // Set app url dynamically if empty + if (!config('app.url')) { + config(['app.url' => url('/')]); + } } protected static function loadCurrencies() diff --git a/config/app.php b/config/app.php index 6d844fa16..54edc76b0 100644 --- a/config/app.php +++ b/config/app.php @@ -55,7 +55,7 @@ return [ | */ - 'url' => env('APP_URL', 'http://localhost'), + 'url' => env('APP_URL', ''), 'asset_url' => env('ASSET_URL', null),