Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Show error if key:generate artisan command fails #44927

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/Illuminate/Foundation/Console/KeyGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ protected function setKeyInEnvironmentFile($key)
return false;
}

$this->writeNewEnvironmentFileWith($key);
if (! $this->writeNewEnvironmentFileWith($key)) {
return false;
}

return true;
}
Expand All @@ -99,15 +101,25 @@ protected function setKeyInEnvironmentFile($key)
* Write a new environment file with the given key.
*
* @param string $key
* @return void
* @return bool
*/
protected function writeNewEnvironmentFileWith($key)
{
file_put_contents($this->laravel->environmentFilePath(), preg_replace(
$replaced = preg_replace(
$this->keyReplacementPattern(),
'APP_KEY='.$key,
file_get_contents($this->laravel->environmentFilePath())
));
$input = file_get_contents($this->laravel->environmentFilePath())
);

if ($replaced === $input || $replaced === null) {
$this->error('Unable to set application key. No APP_KEY variable was found in the .env file.');

return false;
}

file_put_contents($this->laravel->environmentFilePath(), $replaced);

return true;
}

/**
Expand Down