在Laravel 5中动态编辑.env是个好主意吗? [英] Is it a good idea to edit .env dynamically in Laravel 5?

查看:143
本文介绍了在Laravel 5中动态编辑.env是个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建管理面板,因此我需要对Laravel 5应用程序进行一些核心设置(例如smtp设置等),以通过前端界面将其配置为最终用户.

I am building an admin panel, so I need to make some core settings (like smtp settings, etc) of my Laravel 5 app configurable to end users through front-end interface.

我最初的想法是在缓存的同时使用数据库作为设置存储(以避免每次访问配置值时发出数据库调用).但是,看来,外观已在配置文件之后加载,因此下面的代码不起作用:

My initial thoughts were to use database as a settings storage alongside caching(to avoid issuing database calls every time a config value is accessed). However, it appears, that Facades are loaded after config files, thus the code below doesn't work:

<?php
// app/config/custom_settings.php

return [
    'key' => Cache::get('key');
];

因此,我正在考虑以编程方式将用户的配置直接写入.env 文件.这是一个好主意,还是将来会变成头痛?

Because of this, I am thinking about writing the user's configuration directly into .env file programmatically. Is this a good idea, or can it turn into a headache in the future?

推荐答案

为什么不将其存储在数据库,用户表或其他相关表中?

Why don't you store it in your database, in the user's table or in another related table?

我认为.env文件用于全局设置(数据库,邮件配置,缓存配置等),但是它还没有考虑存储最终用户的配置.

I think the .env file is for global settings (database, mail config, cache config,...) but it has not thought to store end user configs.

这篇关于在Laravel 5中动态编辑.env是个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆