[英]Make permanent changes to config files for Laravel 5 via GUI script
I'm using Laravel 5
and building an app that will need to be able to add /edit additional filesystem settings via the application itself, instead of doing so manually. 我正在使用
Laravel 5
并构建一个应用程序,它将需要能够通过应用程序本身来添加/编辑其他文件系统设置,而不是手动进行操作。 I want to be able to add new config settings via a GUI instead of manually. 我希望能够通过GUI而不是手动添加新的配置设置。
I found reference to : this Link but it appears to have some issues with Laravel 5. 我找到了对的引用: 该链接,但是Laravel 5似乎有一些问题。
Is there another / better way to achieve this? 是否有另一种/更好的方法来实现这一目标?
Having your code write to php files doesn't feel right to me. 让您的代码写入php文件对我来说不合适。 Whenever something can be changed by the user, I would store it in your database.
只要用户可以更改某些内容,我就会将其存储在您的数据库中。 It shouldn't be that hard I think.
我认为应该不难。
You could create an Eloquent model like FileSystemConfig
with the required columns to store your filesystem specific config values. 您可以使用所需的列创建诸如
FileSystemConfig
之类的Eloquent模型,以存储特定于文件系统的配置值。 Something like [disk, key, value]
. 诸如
[disk, key, value]
。 Your GUI would just interact with that model to Create / Read / Update / Delete disks. 您的GUI只需与该模型进行交互即可创建/读取/更新/删除磁盘。
To have these 'dynamic' config values be picked up by the application, all you need to do is register them in your ConfigServiceProvider (that should already be present in your App/Providers). 要让应用程序获取这些“动态”配置值,您需要做的就是在ConfigServiceProvider中注册它们(该值应该已经存在于您的App / Providers中)。 That would probably look something like this (untested!)
可能看起来像这样(未经测试!)
class ConfigServiceProvider extends ServiceProvider {
public function register()
{
$fileConfig = FileSystemConfig::all()
->groupBy('disk')
->transform(function($group) {
$out = [];
foreach ($group as $item) {
$out[$item['key']] = $item['value'];
}
return $out;
})
;
config([
'filesystems.disks' => $fileConfig
]);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.