在 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/