PHP code example of proai / laravel-super-migrations

1. Go to this page and download the library: Download proai/laravel-super-migrations 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/ */

    

proai / laravel-super-migrations example snippets




use ProAI\SuperMigrations\Migration;

class InitProject extends Migration
{
    /**
     * Get table names and related methods for up and down schemas.
     *
     * @return array
     */
    public function schemas()
    {
        return [
            'users' => 'create',
            'comments' => 'create'
        ];
    }
}


return [
    'roles' => 'create',
    'users' => 'addRoleIdColumn'
];




use Illuminate\Database\Schema\Blueprint;
use ProAI\SuperMigrations\Table;
use Illuminate\Support\Facades\DB;

class UserTable extends Table
{
    /**
     * Create the table.
     *
     * @return void
     */
    public function create()
    {
        // These statements will be only executed if direction of migrations is up
        $this->upSchema()->create(function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
        });

        $this->up(function($tableName) {
            DB::raw('ALTER TABLE `'.$tableName.'` ADD `client_id` BINARY(16)');
        });


        // These statements will be only executed if direction of migrations is down
        $this->downSchema()->dropIfExists();

        $this->down(function($tableName) {
            // some code
        });
    }
}