Skip to content

Instantly share code, notes, and snippets.

@morrislaptop
Created September 9, 2018 13:02
Show Gist options
  • Save morrislaptop/7a7db9d164bd819317a3519fda6c2874 to your computer and use it in GitHub Desktop.
Save morrislaptop/7a7db9d164bd819317a3519fda6c2874 to your computer and use it in GitHub Desktop.
<?php
namespace App\Bootstrap;
use Dotenv\Dotenv;
use Dotenv\Exception\InvalidFileException;
use Dotenv\Exception\InvalidPathException;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables as BaseLoadEnvironmentVariables;
class LoadEnvironmentVariables extends BaseLoadEnvironmentVariables
{
/**
* Mimic Vue CLI 3 behaviour.
*
* https://github.com/vuejs/vue-cli/issues/1499
*
* .env # loaded in all cases
* .env.local # loaded in all cases, ignored by git
* .env.[mode] # only loaded in specified mode
* .env.[mode].local # only loaded in specified mode, ignored by git
*/
public function bootstrap(Application $app)
{
if ($app->configurationIsCached()) {
return;
}
$this->checkForSpecificEnvironmentFile($app);
if ($app->environmentFile() !== '.env') {
$this->load($app, '.local'); // .env.[APP_ENV].local
$this->load($app); // .env.[APP_ENV]
}
$this->setEnvironmentFilePath($app, '.env');
$this->load($app, '.local'); // .env.local file
$this->load($app); // .env
}
protected function load(Application $app, $suffix = '')
{
try {
(new Dotenv($app->environmentPath(), $app->environmentFile() . $suffix))->load();
} catch (InvalidPathException $e) {
} catch (InvalidFileException $e) {
die('The environment file is invalid: '.$e->getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment