Laravel:检测是否正在运行迁移 [英] Laravel: detect if running migrations

查看:73
本文介绍了Laravel:检测是否正在运行迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一些事件侦听器,我想在其中检测我是否正在运行runnnig数据库迁移或正常的请求/命令.

I have setup some event listeners in which I would like to detect if I'm runnnig database migrations or a normal request/command.

有什么办法知道吗?全局标志?环境?

Is there some way of knowing this? Global flag? Environment?

谢谢.

推荐答案

您可以检查控制台是否与App::runningInConsole()一起使用...根据运行迁移的方式,这是否足够?

You can check if the console is being used with App::runningInConsole() ... that might be sufficient depending on how you are running the migrations.

更新:

好的,在进行了更多挖掘之后,您似乎可以使用以下示例来破解所需信息的方式:

OK, after doing some more digging, it looks like you can hack your way to the info you need using the follow example:

if(app()->runningInConsole()) {
    // we are running in the console
    $argv = \Request::server('argv', null);

    // :$ php artisan migrate:refresh -v
    //
    // gives:
    //
    // $argv = array (
    //      0 => 'artisan',
    //      1 => 'migrate:refresh',
    //      2 => '-v',
    // )  

    if($argv[0] == 'artisan' && \Illuminate\Support\Str::contains($argv[1],'migrate')) {
        // we are running the artisan migrate command
    }
}

来源:如何在Laravel中获取当前控制台命令

这篇关于Laravel:检测是否正在运行迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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