laravel 9在.env文件变量中使用base_path()

发布于 2025-02-09 10:41:34 字数 97 浏览 2 评论 0原文

有一个特殊的字符串模式可以在.env文件变量中使用base_path()?

类似:my_path =%basepath%/my/path

There is a special string pattern to use base_path() into .env file variable ?

Something like : MY_PATH=%basePath%/my/path

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜深人未静 2025-02-16 10:41:34

您可以在.env中使用任何外部环境变量。

例如,您可以在shell调用中设置base_path:

BASE_PATH=/Users/home php artisan my:command

然后,您只需在.env中使用它们,例如,

MY_FILE="${BASE_PATH}/files/something.txt"

我认为您还可以在Web服务器中分配环境变量。

You can use any external environment variables in the .env.

For example, you could set BASE_PATH in a shell call:

BASE_PATH=/Users/home php artisan my:command

Then you simply use them in the .env e.g.

MY_FILE="${BASE_PATH}/files/something.txt"

I think you can also assign environment variables in your web server.

情绪少女 2025-02-16 10:41:34

在.env中,您可以使用上面定义的变量,如果您有许多路径定义,则至少有助于保持文件清洁:

BASE_PATH="/home/to/base"

# The place where you use it must be below the definition,
# otherwise it will literally insert "${BASE_PATH}":

MY_PATH="${BASE_PATH}/my/path"
ANOTHER_PATH="${BASE_PATH}/another/path"

In .env you can use variables that you defined above, which helps at least to keep the file clean if you have many path definitions:

BASE_PATH="/home/to/base"

# The place where you use it must be below the definition,
# otherwise it will literally insert "${BASE_PATH}":

MY_PATH="${BASE_PATH}/my/path"
ANOTHER_PATH="${BASE_PATH}/another/path"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文