Laravel env() 或 config() 在命令行上获取环境变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46710353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:48:06  来源:igfitidea点击:

Laravel env() or config() to get environment variable on command line

phplaravellaravel-5environment-variables

提问by Ryan

I know that running php artisan envon the command line shows me the "Current application environment" (such as "production").

我知道php artisan env在命令行上运行会显示“当前应用程序环境”(例如“生产”)。

But what I want is to be able to see the value of something like env('SESSION_DRIVER')or config('session.driver')straight from the command line.

但我想要的是能够从命令行看到类似env('SESSION_DRIVER')config('session.driver')直接的东西的价值。

Is that possible?

那可能吗?

(I could not find hints in the docs.)

(我在文档中找不到提示。)

回答by Alexey Mezenin

You can run Tinker:

你可以运行 Tinker:

php artisan tinker

And then use any of these commands:

然后使用以下任何命令:

env('SESSION_DRIVER')
config('session.driver')

Tinker allows you to interact with your entire Laravel application on the command line, including the Eloquent ORM, jobs, events, and more.

Tinker 允许您在命令行上与整个 Laravel 应用程序进行交互,包括 Eloquent ORM、作业、事件等。

https://laravel.com/docs/5.5/artisan#introduction

https://laravel.com/docs/5.5/artisan#introduction

Alternatively, you could create an Artisan commandto show you a value from a config file:

或者,您可以创建一个 Artisan 命令来显示配置文件中的值:

php artisan show-config-value session.driver

回答by Neeraja

You can run the artisan commandin CMD or terminal, which displays the current environment the application is executing

您可以在 CMD 或终端中运行artisan 命令,它会显示应用程序正在执行的当前环境

php artisan env