且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Laravel中获取当前的控制台命令

更新时间:2023-01-27 20:13:52

我看不到直接获取Laravel信息的方法.我也不知道怎么可能,因为您可以让一个命令执行其他命令,甚至像某些测试工具一样创建一个新的应用程序实例.

I do not see a way to get that information directly Laravel. I'm also not sure how that would be possible, as you can have one command executing other commands or even creating a new application instance like some test tools do.

但是有一种方法可以使用普通的PHP来实现.您可以检查服务器/环境变量来确定应用程序的执行方式.

There is however a way to achieve that using plain PHP. You can check the server/environment variables to identify how application was executed.

看看

dd($_SERVER['argv']);

如果您运行命令,这应该在 $ _ SERVER ['argv'] [1]

If you run a command this should give you the command name in $_SERVER['argv'][1]

您可以在此处找到更多信息: http://php.net/manual /en/reserved.variables.argv.php

You can find more information here: http://php.net/manual/en/reserved.variables.argv.php