PHP code example of umbrellio / laravel-pg-extensions
1. Go to this page and download the library: Download umbrellio/laravel-pg-extensions 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/ */
umbrellio / laravel-pg-extensions example snippets
Schema::create('table', function (Blueprint $table) {
$table->like('other_table')->includingAll();
$table->ifNotExists();
});
Schema::create('table', function (Blueprint $table) {
$table->integer('number');
});
//modifications with data...
Schema::table('table', function (Blueprint $table) {
$table
->string('number')
->using("('[' || number || ']')::character varying")
->change();
});
// Facade methods:
Schema::createView('active_users', "SELECT * FROM users WHERE active = 1");
Schema::dropView('active_users')
// Schema methods:
Schema::create('users', function (Blueprint $table) {
$table
->createView('active_users', "SELECT * FROM users WHERE active = 1")
->materialize();
});
Schema::table('table', function (Blueprint $table) {
$table->attachPartition('partition')->range([
'from' => now()->startOfDay(), // Carbon will be converted to date time string
'to' => now()->tomorrow(),
]);
});
Schema::table('some_table', function (Blueprint $table) {
// check unique index exists on column
if ($table->hasIndex(['column'], true)) {
$table->dropUnique(['column']);
}
$table->uniquePartial('column')->whereNull('deleted_at');
});
use Umbrellio\Postgres\Extensions\Schema\AbstractBlueprint;
class SomeBlueprint extends AbstractBlueprint
{
public function someMethod()
{
return function (string $column): Fluent {
return $this->addColumn('someColumn', $column);
};
}
}
use Umbrellio\Postgres\PostgresConnection;
use Umbrellio\Postgres\Schema\Blueprint;
use Umbrellio\Postgres\Schema\Grammars\PostgresGrammar;
use Umbrellio\Postgres\Extensions\AbstractExtension;
class SomeExtension extends AbstractExtension
{
public static function getMixins(): array
{
return [
SomeBlueprint::class => Blueprint::class,
SomeConnection::class => PostgresConnection::class,
SomeSchemaGrammar::class => PostgresGrammar::class,
...
];
}
public static function getTypes(): string
{
// where SomeType extends Doctrine\DBAL\Types\Type
return [
'some' => SomeType::class,
];
}
public static function getName(): string
{
return 'some';
}
}
use Illuminate\Support\ServiceProvider;
use Umbrellio\Postgres\PostgresConnection;
class SomeServiceProvider extends ServiceProvider
{
public function register(): void
{
PostgresConnection::registerExtension(SomeExtension::class);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.