Lumen-framework: php artisan migrate --env=testing not working

Created on 20 Apr 2020  路  2Comments  路  Source: laravel/lumen-framework


  • Lumen Version: 5.6
  • Laravel Version: #.#.#
  • PHP Version: 7.2
  • Database Driver & Version: SQLite 3

Description:

Steps To Reproduce:

1/ cp .env .env.testing
2/ SetAPP_ENV=testing
3/ Run php artisan migrate --env=testing

It's still picking from existing .env

Seems below functionality is missing as in laravel

     /**
     * Detect if a custom environment file matching the APP_ENV exists.
     *
     * @param  \Illuminate\Contracts\Foundation\Application  $app
     * @return void
     */
   protected function checkForSpecificEnvironmentFile($app)
    {
        if ($app->runningInConsole() && ($input = new ArgvInput)->hasParameterOption('--env')) {
            if ($this->setEnvironmentFilePath(
                $app, $app->environmentFile().'.'.$input->getParameterOption('--env')
            )) {
                return;
            }
        }

        if (! env('APP_ENV')) {
            return;
        }

        $this->setEnvironmentFilePath(
            $app, $app->environmentFile().'.'.env('APP_ENV')
        );
    }

Most helpful comment

As "--env=xxx" will not be supported (see #1055) I managed to get this working this way:

File: bootstrap\app.php

<?php

require_once __DIR__ . '/../vendor/autoload.php';

$envFileName = ".env";
if (php_sapi_name() == 'cli') {
   $input = new \Symfony\Component\Console\Input\ArgvInput();
   $envParameterOption = $input->getParameterOption('--env');
   if ($input->hasParameterOption('--env') && file_exists(__DIR__ . '/../' . $envFileName . '.' . $envParameterOption)) {
      $envFileName .= '.' . $envParameterOption;
   }
}

(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
   dirname(__DIR__), $envFileName
))->bootstrap();


All 2 comments

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

As "--env=xxx" will not be supported (see #1055) I managed to get this working this way:

File: bootstrap\app.php

<?php

require_once __DIR__ . '/../vendor/autoload.php';

$envFileName = ".env";
if (php_sapi_name() == 'cli') {
   $input = new \Symfony\Component\Console\Input\ArgvInput();
   $envParameterOption = $input->getParameterOption('--env');
   if ($input->hasParameterOption('--env') && file_exists(__DIR__ . '/../' . $envFileName . '.' . $envParameterOption)) {
      $envFileName .= '.' . $envParameterOption;
   }
}

(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
   dirname(__DIR__), $envFileName
))->bootstrap();


Was this page helpful?
0 / 5 - 0 ratings

Related issues

rtheunissen picture rtheunissen  路  3Comments

rmblstrp picture rmblstrp  路  5Comments

matthewsuan picture matthewsuan  路  3Comments

codercms picture codercms  路  4Comments

jampack picture jampack  路  3Comments