Laravel 4.1 Run migrations and update configuration from package dependencies

和自甴很熟 提交于 2019-12-24 13:07:54

问题


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

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.

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?

Thanks

EDIT:
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')
        );
    }
}

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


回答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'));

Docs: http://laravel.com/docs/commands#calling-other-commands

On older versions:

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

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


来源:https://stackoverflow.com/questions/22131826/laravel-4-1-run-migrations-and-update-configuration-from-package-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!