Skip to content

hughcube/laravel-migration

Repository files navigation

Laravel Migration Extension

Test Actions status Lint Actions status StyleCI Code Coverage Scrutinizer Code Quality Code Intelligence Status PHP Versions Supported Latest Stable Version Total Downloads License Latest Unstable Version composer.lock available

Installing

$ composer require hughcube/laravel-migration -vvv

Basic Usage (In artisan file)

#!/usr/bin/env php
<?php

use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| First we need to get an application instance. This creates an instance
| of the application / container and bootstraps the application so it
| is ready to receive HTTP / Console requests from the environment.
|
*/
$app = require __DIR__ . '/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/
$kernel = $app->make(
    'Illuminate\Contracts\Console\Kernel'
);

/** !!! Register after kernel is created  */
$app->register(\HughCube\Laravel\Migrations\ServiceProvider::class);

exit($kernel->handle(new ArgvInput, new ConsoleOutput));

Example

<?php

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

class CreateExampleTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('example', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            
            /** Set table comment */
            $table->comment = "Example";
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('example');
    }
}