php - Laravel 中间件抛出 "No supported encrypter found"消息

标签 php laravel ubuntu encryption laravel-artisan

在 laravel 5.2 中
简单地说,这段代码工作得更好:

Route::get('/', function () {
if(Auth::guest())
{
    return Redirect::to('login');
}
else
{
    return view('index');   
}

});

并且此代码不起作用并抛出“找不到支持的加密器。密码和/或 key 长度无效”的消息。
Route::group(['middleware' => ['web']], function () {
//

Route::get('/',function(){
    return view('index');
})->middleware('auth');
});

即使我测试了 laravel 的默认 artisan make:auth,它仍然显示相同的消息。
我认为这不是关键,因为我可以使用第一种方法登录但不能使用中间件。
帮助...

更新:
.env 文件和 config/app.php 文件中的 key 是相同的 32 字符 key ,并且 'cipher' => 'AES-256-CBC'

更新 2
在帮助并检查 Illuminate/Encryption/EncryptionServiceProvider.php 之后,我发现:
$config = $app->make('config')->get('app');
$key = $config['key'];
$cipher = $config['cipher'];

当我尝试回显 $cipher 值时,我发现它是 'AES-256-CBC',就像在配置文件中一样,但 $key 变量为空。那么它为什么不从配置文件或 .env 文件中读取 key ???

最佳答案

在 App.php 文件中有这样的内容:

'key' => env('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')

应该是
'key' => env('APP_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')

或者
'key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

关于php - Laravel 中间件抛出 "No supported encrypter found"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35780709/

相关文章:

javascript - 在 html 文本区域中按 Enter 键时如何使用 jquery 添加换行符

php - 使用 session php 从 id 中选择?

bash - 在 bash 脚本中使用 if 语句检查包是否已安装时遇到问题

ubuntu - 解决 conda 环境卡住

git - 远程 : Invalid username or password

php - 获取等于或大于并为空的记录

php - 命名 cookie - 最佳实践

apache - Laravel 服务在本地主机上收到 ERR_CONNECTION_REFUSED

php - Faker 软件包、数据库播种器问题

php - Eloquent 多对多关系上的总和数据透视表字段