Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 钩住laravel 4 artisan命令_Php_Laravel_Laravel 4 - Fatal编程技术网

Php 钩住laravel 4 artisan命令

Php 钩住laravel 4 artisan命令,php,laravel,laravel-4,Php,Laravel,Laravel 4,有没有一种方法可以轻松地钩住artisan命令?我希望在每次执行php artisan migrate命令时都能执行一段代码。您可以扩展Schema Builder facade并覆盖构建函数,如下所示: protected function build(Blueprint $blueprint) { your_function(); Parent::build($blueprint); } 但是,在使用迁移的--佯装选项时,不会调用函数。我不知道有什么内置方法可以在不

有没有一种方法可以轻松地钩住artisan命令?我希望在每次执行
php artisan migrate
命令时都能执行一段代码。

您可以扩展Schema Builder facade并覆盖构建函数,如下所示:

protected function build(Blueprint $blueprint)
{
      your_function();
      Parent::build($blueprint);
}

但是,在使用迁移的--佯装选项时,不会调用函数。我不知道有什么内置方法可以在不扩展Schema Builder或Migrator类的情况下连接到迁移中。

您可以扩展Schema Builder facade并覆盖构建函数,如下所示:

protected function build(Blueprint $blueprint)
{
      your_function();
      Parent::build($blueprint);
}

但是,在使用迁移的--佯装选项时,不会调用函数。我不知道有什么内置方法可以在不扩展Schema Builder或Migrator类的情况下连接到迁移中。

只需在代码中的某个位置(甚至在app/start/artisan.php的顶部)添加一个侦听器,以侦听“artisan.start”事件

Event::listen('artisan.start', function($app)
{
    // $app is instance of Illuminate\Console\Application
    // since the $app hasn't figured the command yet you'll
    // have to do it yourself to check if it's the migrate command
});

只需在代码中的某个位置(甚至在app/start/artisan.php的顶部)添加一个侦听器,以侦听“artisan.start”事件

Event::listen('artisan.start', function($app)
{
    // $app is instance of Illuminate\Console\Application
    // since the $app hasn't figured the command yet you'll
    // have to do it yourself to check if it's the migrate command
});

您可以尝试以下方法(您可以将其放入
filters.php
文件中):


您可以尝试以下方法(您可以将其放入
filters.php
文件中):


您可以扩展或it调用。您可以扩展或it调用。