質問

Currently i'm running db migrations from commandline like so :

> php artisan migrate:make foo --create:footable

> php artisan migrate

But how can i run Laravel 4 migrations from a non-Laravel script? Instead of the usual artisan migarte commands, or even the Artisan::call() instruction.

Just to clarify, i need to run already created migrations.

役に立ちましたか?

解決

In Laravel 4.1+, the following does not work:

Artisan::call('migrate', array('option' => '--bench', 'argument' => 'vendor/package'))
Throws : The "option" argument does not exist.

Artisan::call('migrate --package=vendor/package');
Throws : Command "migrate --bench=vendor/package" is not defined

But this does:

Artisan::call('migrate', array('--bench'=>'vendor/package'))

他のヒント

You will have to boot your a Laravel application by doing:

<?php

require 'vendor/autoload.php';
require 'bootstrap/start.php';

Then you will have access to the $app global variable, which holds the whole Laravel application, including Artisan, so you'll be able to:

Artisan::call('migrate');

and

$app['artisan']->call('migrate');

If you have an external namespaced class, like this one:

<?php namespace App\Example; 

require 'vendor/autoload.php'; 
require 'bootstrap/start.php'; 

use Form;
use Artisan;

class Example { 

    public function make() { 

        Artisan::call('migrate');

    } `enter code here`

}

You can call it using:

<?php

require 'Example.php';

use App\Example\Example;

$s = new Example;

dd($s->make());

This is not advisable, but as a last resort, you can use:

return $GLOBALS['app']['artisan']->call('migrate');
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top