Skip to content
This repository has been archived by the owner on Aug 18, 2022. It is now read-only.

Commit

Permalink
Use a more dependable way to find the .env file.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcordingley committed Jun 30, 2017
1 parent 6f9a5ee commit 3370b2b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Console/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ final protected function confirmOverwrite(string $key): bool
*/
final protected function writeConfigurationValue(string $key, string $value)
{
$contents = file_get_contents($this->laravel->environmentFilePath());

$pattern = "/^$key=.*$/m";
$line = $key . '=' . $value;

file_put_contents(
$this->laravel->environmentFilePath(),
preg_match($pattern, $contents) ? preg_replace($pattern, $line, $contents) : $contents . "\n" . $line
);
$filePath = $this->laravel->basePath() . '/.env';
$contents = file_get_contents($filePath);
$updated = preg_match($pattern, $contents) ? preg_replace($pattern, $line, $contents) : $contents . "\n" . $line;

file_put_contents($filePath, $updated);
}
}

0 comments on commit 3370b2b

Please sign in to comment.