Laravel 4.1运行迁移并从软件包依赖项更新配置 [英] Laravel 4.1 Run migrations and update configuration from package dependencies

查看:78
本文介绍了Laravel 4.1运行迁移并从软件包依赖项更新配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用哨兵2 的Laravel 4软件包. 为了安装哨兵2 ,我必须运行迁移并发布其配置:

I'm developing a Laravel 4 package that uses Sentry 2. In order for Sentry 2 to be installed I have to run migrations and publish their configurations:

php artisan migrate --package=cartalyst/sentry
php artisan config:publish cartalyst/sentry

我想允许我软件包的用户为我自己的软件包运行迁移并发布配​​置,而不必为Sentry 2或我可能需要的任何其他软件包运行配置.

I would like to allow users of my package to simply run the migrations and publish configs for my own package without having to run that for Sentry 2, or any other package that I might require.

有没有办法做到这一点?应该完全做到这一点,还是我应该继续要求用户为每个软件包运行迁移/发布conf?

Is there any way to do this? Should this be done at all, or should I keep asking my users to run the migrations/publish confs for every package?

谢谢


顺带一提,我遵循了@AntonioCarlosRibeiro的建议,并创建了一个新的Artisan命令:


As promissed, I've followed @AntonioCarlosRibeiro proposal and created a new Artisan command:

class SybilInstall extends Command
{
    protected $name = 'sybil:install';
    protected $description = 'Install the sybil package';
    public function fire()
    {
        $this->call(
            'migrate',
            array('--package' => 'cartalyst/sentry')
        );
        $this->call(
            'migrate',
            array('--package' => 'ghunti/sybil')
        );
        $this->call(
            'asset:publish',
            array('ghunti/sybil')
        );
    }
}

现在人们只需要运行php artisan sybil:install,它将处理所有事情

Now people onlye need to run php artisan sybil:install and it will take care of everything

推荐答案

在您的包中,您可以运行(Laravel 4.1 +):

Inside your package you can run (Laravel 4.1+):

Artisan::call('migrate', array('option' => '--package', 'argument' => 'cartalyst/sentry'));

Artisan::call('config:publish', array('argument' => 'cartalyst/sentry'));

文档: http://laravel.com/docs/commands#calling-other-命令

在旧版本上:

Artisan::call('migrate --package=cartalyst/sentry');

Artisan::call('config:publish cartalyst/sentry'):

这篇关于Laravel 4.1运行迁移并从软件包依赖项更新配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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