1. Go to this page and download the library: Download efureev/laravel-support-db 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/ */
$table->primaryUUID(); // create PK UUID-column with name `id`
$table->primaryUUID('custom_name'); // create PK UUID-column with name `custom_name`
// create UUID-column with name `id`. Generate UUID-value by DB.
$table->generateUUID();
// create UUID-column with name `cid`. Generate UUID-value by DB.
$table->generateUUID('cid');
// create UUID-column with name `cid`. NOT generate UUID-value by DB. Set `nullable`. Default value: `NULL`.
$table->generateUUID('id', null);
// create UUID-column with name `cid`. NOT generate UUID-value by DB. Set `nullable`. Default value: `NULL`. Create Index by this column.
$table->generateUUID('fk_id', null)->index();
// create UUID-column with name `fk_id`. NOT generate UUID-value by DB.
$table->generateUUID('fk_id', false);
// create UUID-column with name `fk_id`. Generate UUID-value by DB with custom value.
$table->generateUUID('fk_id', fn($column)=>'uuid_generate_v5()');
// create UUID-column with name `fk_id`. Generate UUID-value by DB with custom value.
$table->generateUUID('fk_id', new Expression('uuid_generate_v2()'));
$table->xml(string $column);
$table->uuidArray(string $column);
$table->intArray(string $column);
$table->textArray(string $column);
$table->string('col')->compression('lz4');
// Facade methods:
Schema::createView('active_users', "SELECT * FROM users WHERE active = 1");
Schema::createView('active_users', "SELECT * FROM users WHERE active = 1", true) ;
Schema::createViewOrReplace('active_users', "SELECT * FROM users WHERE active = 1");
// Schema methods:
use \Php\Support\Laravel\Database\Schema\Postgres\Blueprint;
Schema::create('users', function (Blueprint $table) {
$table
->createView('active_users', "SELECT * FROM users WHERE active = 1")
->materialize();
});
use \Php\Support\Laravel\Database\Schema\Postgres\Blueprint;
Schema::create('table', static function (Blueprint $table) {
$table->string('code');
$table->softDeletes();
$table
->partial('code')
->whereNull('deleted_at');
});
use \Php\Support\Laravel\Database\Schema\Postgres\Blueprint;
Schema::create('table', static function (Blueprint $table) {
$table->dropPartial(['code']);
});
use \Php\Support\Laravel\Database\Schema\Postgres\Blueprint;
Schema::create('table', static function (Blueprint $table) {
$table->string('code');
$table->softDeletes();
$table
->uniquePartial('code')
->whereNull('deleted_at');
});
use \Php\Support\Laravel\Database\Schema\Postgres\Blueprint;
Schema::create('table', static function (Blueprint $table) {
$table->dropUniquePartial(['code']);
});
Schema::create('target_table', function (Blueprint $table) {
$table->like('source_table')->includingAll();
$table->ifNotExists();
});
Schema::create('target_table', function (Blueprint $table) {
$table->fromTable('source_table');
});
Schema::create('target_table', function (Blueprint $table) {
$table->fromSelect('select id, name from source_table');
});
// or
Schema::create('target_table', function (Blueprint $table) {
$table->fromSelect(
'select t1.id, t2.enabled, t2.extra from source_table t1 ' .
'join source_table_2 t2 on t1.id = t2.src_id ' .
'where t2.enabled = true'
);
});
// or
$tbl = 'source_table';
Schema::create(
$tbl,
static function (Blueprint $table) {
$table->string('key', 16)->primary();
$table->string('title');
$table->integer('sort')->index();
}
);
// or
Schema::create(self::TGT_TABLE, function (Blueprint $table) use ($tbl) {
Schema::createExtensionIfNotExists('uuid-ossp');
$table->fromSelect(
'select uuid_generate_v4() as id, key, title, sort from ' . $tbl
);
});
// or
Schema::create(self::TGT_TABLE, function (Blueprint $table) use ($tbl) {
Schema::createExtensionIfNotExists('uuid-ossp');
$table->fromSelect(
'select uuid_generate_v4() as id, * ' . $tbl
);
});