PHP code example of artesaos / migrator

1. Go to this page and download the library: Download artesaos/migrator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

artesaos / migrator example snippets


'providers' => [
    // other providers omitted.
    Migrator\MigrationServiceProvider::class,
]



namespace MyApp\MyModule\Database\Migrations;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{
    /**
     * @var \Illuminate\Database\Schema\Builder
     */
    protected $schema;

    /**
     * Migration constructor.
     */
     public function __construct()
     {
         $this->schema = app('db')->connection()->getSchemaBuilder();
     }

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $this->schema->create('orders', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $this->schema->drop('orders');
    }
}



namespace MyApp\MyModule\Providers;

use Illuminate\Support\ServiceProvider;
use Migrator\MigratorTrait;
use MyApp\MyModule\Database\Migrations\CreateOrdersTable;
use MyApp\MyModule\Database\Migrations\CreateProductsTable;

class MyModuleServiceProvider extends ServiceProvider
{
    use MigratorTrait;
    
    public function register()
    {
        $this->migrations([
            CreateOrdersTable::class,
            CreateProductsTable::class,
        ]);
    }
}

php artisan vendor:publish --provider="Migrator\MigrationServiceProvider"