如何检查当前应用程序进程是否在 Laravel 的队列环境中运行

Lor*_*izy 2 laravel

我通过特征将全局范围应用于我的模型,但我不希望在从 Redis 队列调用/处理模型时应用全局范围。

如何检测当前实例是否是队列进程?就像我们有这个

if (App::environment('local')) {
    // The environment is local
}
Run Code Online (Sandbox Code Playgroud)

检测应用程序是否在本地或生产中运行。

Leo*_*ent 5

只需调用该runningInConsole()方法

if (app()->runningInConsole()) {
Run Code Online (Sandbox Code Playgroud)

或使用应用程序外观

if (\App::runningInConsole()) {
Run Code Online (Sandbox Code Playgroud)

通过 CLI 检查是否正在执行。