Search code examples
phplaravelmigrationlaravel-artisan

Call artisan in laravel with migrate:make


Run artisan commands from routes or controller. If you want run your migrations make:

Artisan::call('migrate:make');

but have not migrate name. How to run command : "migrate:make NameMigrate" and use Artisan::call


Solution

  • I don't like the idea of creating migration in controller, but you surely can perform it.

    Laravel 4:

    Artisan::call('migrate:make', ['name' => 'migration_name']);
    

    Laravel 5:

    Artisan::call('make:migration', ['name' => 'migration_name']);
    

    Don't forget to grant write permission to migrations folder so your application can write files to that folder.

    Laravel 4: chmod 777 database/migrations

    Laravel 5: chmod 777 app/database/migrations