diff --git a/src/Illuminate/Encryption/EncryptionServiceProvider.php b/src/Illuminate/Encryption/EncryptionServiceProvider.php index d27ed2826123..ad365becc4eb 100755 --- a/src/Illuminate/Encryption/EncryptionServiceProvider.php +++ b/src/Illuminate/Encryption/EncryptionServiceProvider.php @@ -2,6 +2,7 @@ namespace Illuminate\Encryption; +use RuntimeException; use Illuminate\Support\Str; use Illuminate\Support\ServiceProvider; @@ -17,10 +18,18 @@ public function register() $this->app->singleton('encrypter', function ($app) { $config = $app->make('config')->get('app'); + $key = $config['key']; + + if (is_null($key) || $key === '') { + throw new RuntimeException( + 'The application encryption key is missing. Run php artisan key:generate to generate it.' + ); + } + // If the key starts with "base64:", we will need to decode the key before handing // it off to the encrypter. Keys may be base-64 encoded for presentation and we // want to make sure to convert them back to the raw bytes before encrypting. - if (Str::startsWith($key = $config['key'], 'base64:')) { + if (Str::startsWith($key, 'base64:')) { $key = base64_decode(substr($key, 7)); }