有任何方法可以改变我的.env文件值从控制器在拉拉?
我找到了this answer,但它回来了
未定义属性: App\Http\Controllers\Admin\PerformanceController::$laravel
代码
$path = base_path('.env');
$key = false;
if (file_exists($path)) {
file_put_contents($path, str_replace(
'APP_KEY='.$this->laravel['config']['app.key'], 'APP_DEBUG='.$key, file_get_contents($path)
));
}我希望在我的管理面板中有选项在真或假之间改变调试模式,就像我们在控制器中有类似于Artisan::call('down')或Artisan::call('up')的手工命令一样。
更新
现在我有了这个代码
$path = base_path('.env');
$key = 'true';
if (file_exists($path)) {
file_put_contents($path, str_replace(
'APP_DEBUG='.config('app.debug'), 'APP_DEBUG='.$key, file_get_contents($path)
));
}这段代码确实有效,但问题是它没有删除旧值。
在此之前
APP_DEBUG=false之后
APP_DEBUG=truefalse
or
APP_DEBUG=falsefalse知道吗?
发布于 2019-01-24 06:35:57
更改您的.env配置不是个好主意。在您想要更改APP_KEY的地方使用下面的代码来代替它。
确保您没有缓存您的配置
config(['app.key' => 'YOUR_NEW_KEY']);发布于 2019-01-24 07:02:01
而不是使用$this->laravel['config']['app.key'],尝试config('app.key')
发布于 2021-01-12 18:08:47
使用这个DotenvEditor::setKey('APP_KEY','new_value')->save();
https://stackoverflow.com/questions/54340561
复制相似问题