PHP code example of mylesduncanking / laravel-simple-migration

1. Go to this page and download the library: Download mylesduncanking/laravel-simple-migration 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/ */

    

mylesduncanking / laravel-simple-migration example snippets


protected array $migration = [
    'TABLE NAME' => [
        'COLUMN NAME' => ['COLUMN MODIFIERS' /** Additional modifiers **/],
        /* Additional columns */
    ],
    /* Additional tables */
];

protected array $migration = [
    /* This table would be created as it contains an 'id' column */
    'table_to_be_created' => [
        'id'
        'name',
        'date:dob' => ['nullable'],
        'timestamps',
    ],

    /* This table would be updated as it doesn't contains an 'id' or 'uuid' column */
    'table_to_be_updated' => [
        'name' => ['after:id']
    ],

    /* A table of name "pivot_table" would be created as the method has been defined */
    'create:pivot_table' => [
        'foreignId:key_1' => ['index'],
        'foreignId:key_2' => ['index'],
    ],
];



use MylesDuncanKing\SimpleMigration\SimpleMigration;

class ExampleMigration extends SimpleMigration
{
    protected array $migration = [
        // Create "roles" table as "id" column is specified
        'roles' => [
            'id',                                       // $table->id();
            'softDeletes',                              // $table->softDeletes();
            'string:role,64',                           // $table->string('role', 64);
            'unique:deleted_at|role,roles_unique_role', // $table->unique(['deleted_at', 'role'], 'roles_unique_role');
        ],

        // Update "users" table as no "id" or "uuid" column is specified
        'users' => [
            'role_id' => ['after:id', 'nullable'],       // ends in _id so $table:foreignId('role_id')->after('id')->nullable()->index();
            'foreign:role_id' => ['references:id', 'on:roles'],   // $table->foreign('role_id')->references('id')->on('roles')->index();
        ]
    ];
}