Migration

Laravel Migration

Set the Default Value of a Timestamp Column to the Current Timestamp with Laravel Migrations

$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();

Create a PostgreSQL GIST index on a Laravel migration

Create table mode

use Illuminate\Support\Facades\Schema;

public function up()
{
    Schema::table('table_name', function (Blueprint $table) {
        $table->index('column_name', 'index_name', 'gist');
    });
}

Alter table mode

use Illuminate\Support\Facades\Schema;

public function up()
{
    Schema::table('table_name', function (Blueprint $table) {
        $table->addIndex('column_name', 'index_name', 'gist');
    });
}

Custom Add Index

use Illuminate\Support\Facades\Schema;

public function up()
{
    Schema::table('table_name', function (Blueprint $table) {
        $table->string('column_name');
    });

    DB::statement('CREATE INDEX index_name ON table_name USING gist (column_name)');
    // Specify the index algorithm to the inet_ops
    DB::statement('CREATE INDEX gn_network ON geoip2_network USING gist (network inet_ops)');
}

Create foreign key on the migration

Schema::create('orders', function (Blueprint $table) {
    $table->id();
    $table->unsignedBigInteger('customer_id');
    $table->foreign('customer_id')->references('id')->on('customers');
    // ...
});

Reference