class Builder

Traits

Constants

protected DEFAULT_STRING_LENGTH

protected DEFAULT_TIME_PRECISION

protected DEFAULT_MORPH_KEY_TYPE

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected Connection $connection

The database connection instance.

protected Grammar $grammar

The schema grammar instance.

protected Connection, string, null|Blueprint $resolver

The Blueprint resolver callback.

static null|non-negative-int $defaultStringLength

The default string length for migrations.

static int|null $defaultTimePrecision

The default time precision for migrations.

static "int"|"ulid"|"uuid" $defaultMorphKeyType

The default relationship morph key type.

Methods

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

__construct(Connection $connection)

Create a new database Schema manager.

static void
defaultStringLength(int $length)

Set the default string length for migrations.

static void
defaultTimePrecision(int|null $precision)

Set the default time precision for migrations.

static void
defaultMorphKeyType(string $type)

Set the default morph key type for migrations.

static void
morphUsingUuids()

Set the default morph key type for migrations to UUIDs.

static void
morphUsingUlids()

Set the default morph key type for migrations to ULIDs.

bool
createDatabase(string $name)

Create a database in the schema.

bool
dropDatabaseIfExists(string $name)

Drop a database from the schema if the database exists.

array
getSchemas()

Get the schemas that belong to the connection.

bool
hasTable(string $table)

Determine if the given table exists.

bool
hasView(string $view)

Determine if the given view exists.

array
getTables(array|string|null $schema = null)

Get the tables that belong to the connection.

array
getTableListing(array|string|null $schema = null, bool $schemaQualified = true)

Get the names of the tables that belong to the connection.

array
getViews(array|string|null $schema = null)

Get the views that belong to the connection.

array
getTypes(array|string|null $schema = null)

Get the user-defined types that belong to the connection.

bool
hasColumn(string $table, string $column)

Determine if the given table has a given column.

bool
hasColumns(string $table, array $columns)

Determine if the given table has given columns.

void
whenTableHasColumn(string $table, string $column, Closure $callback)

Execute a table builder callback if the given table has a given column.

void
whenTableDoesntHaveColumn(string $table, string $column, Closure $callback)

Execute a table builder callback if the given table doesn't have a given column.

void
whenTableHasIndex(string $table, array|string $index, Closure $callback, string|null $type = null)

Execute a table builder callback if the given table has a given index.

void
whenTableDoesntHaveIndex(string $table, array|string $index, Closure $callback, string|null $type = null)

Execute a table builder callback if the given table doesn't have a given index.

string
getColumnType(string $table, string $column, bool $fullDefinition = false)

Get the data type for the given column name.

array
getColumnListing(string $table)

Get the column listing for a given table.

array
getColumns(string $table)

Get the columns for a given table.

array
getIndexes(string $table)

Get the indexes for a given table.

array
getIndexListing(string $table)

Get the names of the indexes for a given table.

string
qualifyIndexName(string $name)

Qualify an explicit index name.

bool
hasIndex(string $table, array|string $index, string|null $type = null)

Determine if the given table has a given index.

bool
hasForeignKey(string $table, array|string $foreignKey)

Determine if the table has a given foreign key.

array
getForeignKeys(string $table)

Get the foreign keys for a given table.

void
table(string $table, Closure $callback)

Modify a table on the schema.

void
create(string $table, Closure $callback)

Create a new table on the schema.

void
createMigrationRepositoryTable(string $table)

Create the migration repository table for this database driver.

void
drop(string $table)

Drop a table from the schema.

void
dropIfExists(string $table)

Drop a table from the schema if it exists.

void
dropColumns(string $table, array|string $columns)

Drop columns from a table schema.

void
dropAllTables()

Drop all tables from the database.

void
dropAllViews()

Drop all views from the database.

void
dropAllTypes()

Drop all types from the database.

void
truncateTables(array $tables)

Truncate the given tables if they contain rows.

void
rename(string $from, string $to)

Rename a table on the schema.

bool
enableForeignKeyConstraints()

Enable foreign key constraints.

bool
disableForeignKeyConstraints()

Disable foreign key constraints.

mixed
withoutForeignKeyConstraints(Closure $callback)

Disable foreign key constraints during the execution of a callback.

bool
foreignKeyConstraintsAreEnabled()

Determine whether foreign key constraints are enabled.

void
setForeignKeyConstraints(bool $enabled)

Set the foreign key constraint state for an internal suppression scope.

void
executeSessionStatement(string $statement)

Execute internal physical-session maintenance.

void
ensureVectorExtensionExists(string|null $schema = null)

Create the vector extension on the schema if it does not exist.

void
ensureExtensionExists(string $name, string|null $schema = null)

Create a new extension on the schema if it does not exist.

void
executeBlueprint(Blueprint $blueprint)

Execute the given schema blueprint.

void
build(Blueprint $blueprint)

Execute the blueprint to build / modify the table.

void
executeStatements(array $statements)

Execute the given schema statements in order.

array
selectMetadata(string $query)

Read schema metadata from the same write connection that migrations mutate.

mixed
scalarMetadata(string $query)

Read a scalar result through the metadata execution hook.

bool
commandsAreDeclaredOn(Blueprint $blueprint, string $grammar)

Determine whether every executable command is declared by the framework grammar.

createBlueprint(string $table, Closure|null $callback = null)

Create a new command set with a Closure.

array|null
getCurrentSchemaListing()

Get the names of the current schemas for the connection.

string|null
getCurrentSchemaName()

Get the default schema name for the connection.

array
parseSchemaAndTable(string $reference, bool|string|null $withDefaultSchema = null)

Parse the given database object reference and extract the schema and table.

getConnection()

Get the database connection instance.

void
blueprintResolver(Closure $resolver)

Set the Schema Blueprint resolver callback.

static void
flushState()

Flush all static state.

Details

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 67
__construct(Connection $connection)

Create a new database Schema manager.

Parameters

Connection $connection

at line 81
static void defaultStringLength(int $length)

Set the default string length for migrations.

Boot-only. The length persists in a static property for the worker lifetime and applies to every Blueprint::string() across all coroutines.

Parameters

int $length

Return Value

void

at line 92
static void defaultTimePrecision(int|null $precision)

Set the default time precision for migrations.

Boot-only. The precision persists in a static property for the worker lifetime and applies to every time/datetime column across all coroutines.

Parameters

int|null $precision

Return Value

void

at line 105
static void defaultMorphKeyType(string $type)

Set the default morph key type for migrations.

Boot-only. The type persists in a static property for the worker lifetime and applies to every morph() column across all coroutines.

Parameters

string $type

Return Value

void

Exceptions

InvalidArgumentException

at line 119
static void morphUsingUuids()

Set the default morph key type for migrations to UUIDs.

Boot-only. Sets the worker-wide morph type via defaultMorphKeyType().

Return Value

void

at line 129
static void morphUsingUlids()

Set the default morph key type for migrations to ULIDs.

Boot-only. Sets the worker-wide morph type via defaultMorphKeyType().

Return Value

void

at line 137
bool createDatabase(string $name)

Create a database in the schema.

Parameters

string $name

Return Value

bool

at line 147
bool dropDatabaseIfExists(string $name)

Drop a database from the schema if the database exists.

Parameters

string $name

Return Value

bool

at line 159
array getSchemas()

Get the schemas that belong to the connection.

Return Value

array

at line 169
bool hasTable(string $table)

Determine if the given table exists.

Parameters

string $table

Return Value

bool

at line 191
bool hasView(string $view)

Determine if the given view exists.

Parameters

string $view

Return Value

bool

at line 212
array getTables(array|string|null $schema = null)

Get the tables that belong to the connection.

Parameters

array|string|null $schema

Return Value

array

at line 224
array getTableListing(array|string|null $schema = null, bool $schemaQualified = true)

Get the names of the tables that belong to the connection.

Parameters

array|string|null $schema
bool $schemaQualified

Return Value

array

at line 237
array getViews(array|string|null $schema = null)

Get the views that belong to the connection.

Parameters

array|string|null $schema

Return Value

array

at line 249
array getTypes(array|string|null $schema = null)

Get the user-defined types that belong to the connection.

Parameters

array|string|null $schema

Return Value

array

at line 259
bool hasColumn(string $table, string $column)

Determine if the given table has a given column.

Parameters

string $table
string $column

Return Value

bool

at line 272
bool hasColumns(string $table, array $columns)

Determine if the given table has given columns.

Parameters

string $table
array $columns

Return Value

bool

at line 289
void whenTableHasColumn(string $table, string $column, Closure $callback)

Execute a table builder callback if the given table has a given column.

Parameters

string $table
string $column
Closure $callback

Return Value

void

at line 299
void whenTableDoesntHaveColumn(string $table, string $column, Closure $callback)

Execute a table builder callback if the given table doesn't have a given column.

Parameters

string $table
string $column
Closure $callback

Return Value

void

at line 309
void whenTableHasIndex(string $table, array|string $index, Closure $callback, string|null $type = null)

Execute a table builder callback if the given table has a given index.

Parameters

string $table
array|string $index
Closure $callback
string|null $type

Return Value

void

at line 319
void whenTableDoesntHaveIndex(string $table, array|string $index, Closure $callback, string|null $type = null)

Execute a table builder callback if the given table doesn't have a given index.

Parameters

string $table
array|string $index
Closure $callback
string|null $type

Return Value

void

at line 331
string getColumnType(string $table, string $column, bool $fullDefinition = false)

Get the data type for the given column name.

Parameters

string $table
string $column
bool $fullDefinition

Return Value

string

Exceptions

InvalidArgumentException

at line 349
array getColumnListing(string $table)

Get the column listing for a given table.

Parameters

string $table

Return Value

array

at line 359
array getColumns(string $table)

Get the columns for a given table.

Parameters

string $table

Return Value

array

at line 377
array getIndexes(string $table)

Get the indexes for a given table.

Parameters

string $table

Return Value

array

at line 395
array getIndexListing(string $table)

Get the names of the indexes for a given table.

Parameters

string $table

Return Value

array

at line 407
string qualifyIndexName(string $name)

Qualify an explicit index name.

The configured table prefix is applied only when index prefixing is enabled. Names are always lowercased, with dashes and dots normalized to underscores to match generated index names.

Parameters

string $name

Return Value

string

at line 419
bool hasIndex(string $table, array|string $index, string|null $type = null)

Determine if the given table has a given index.

Parameters

string $table
array|string $index
string|null $type

Return Value

bool

at line 442
bool hasForeignKey(string $table, array|string $foreignKey)

Determine if the table has a given foreign key.

Parameters

string $table
array|string $foreignKey

Return Value

bool

at line 458
array getForeignKeys(string $table)

Get the foreign keys for a given table.

Parameters

string $table

Return Value

array

at line 474
void table(string $table, Closure $callback)

Modify a table on the schema.

Parameters

string $table
Closure $callback

Return Value

void

at line 482
void create(string $table, Closure $callback)

Create a new table on the schema.

Parameters

string $table
Closure $callback

Return Value

void

at line 494
void createMigrationRepositoryTable(string $table)

Create the migration repository table for this database driver.

Parameters

string $table

Return Value

void

at line 509
void drop(string $table)

Drop a table from the schema.

Parameters

string $table

Return Value

void

at line 519
void dropIfExists(string $table)

Drop a table from the schema if it exists.

Parameters

string $table

Return Value

void

at line 531
void dropColumns(string $table, array|string $columns)

Drop columns from a table schema.

Parameters

string $table
array|string $columns

Return Value

void

at line 543
void dropAllTables()

Drop all tables from the database.

Return Value

void

Exceptions

LogicException

at line 553
void dropAllViews()

Drop all views from the database.

Return Value

void

Exceptions

LogicException

at line 563
void dropAllTypes()

Drop all types from the database.

Return Value

void

Exceptions

LogicException

at line 573
void truncateTables(array $tables)

Truncate the given tables if they contain rows.

Parameters

array $tables

Return Value

void

at line 588
void rename(string $from, string $to)

Rename a table on the schema.

Parameters

string $from
string $to

Return Value

void

at line 598
bool enableForeignKeyConstraints()

Enable foreign key constraints.

Return Value

bool

at line 608
bool disableForeignKeyConstraints()

Disable foreign key constraints.

Return Value

bool

at line 623
mixed withoutForeignKeyConstraints(Closure $callback)

Disable foreign key constraints during the execution of a callback.

Parameters

Closure $callback

Return Value

mixed

at line 655
protected bool foreignKeyConstraintsAreEnabled()

Determine whether foreign key constraints are enabled.

Drivers that cannot inspect the current mode report enabled so the outer scope applies and restores their normal constraint mode.

Return Value

bool

at line 663
protected void setForeignKeyConstraints(bool $enabled)

Set the foreign key constraint state for an internal suppression scope.

Parameters

bool $enabled

Return Value

void

at line 683
protected void executeSessionStatement(string $statement)

Execute internal physical-session maintenance.

Parameters

string $statement

Return Value

void

at line 691
void ensureVectorExtensionExists(string|null $schema = null)

Create the vector extension on the schema if it does not exist.

Parameters

string|null $schema

Return Value

void

at line 701
void ensureExtensionExists(string $name, string|null $schema = null)

Create a new extension on the schema if it does not exist.

Parameters

string $name
string|null $schema

Return Value

void

Exceptions

RuntimeException

at line 718
void executeBlueprint(Blueprint $blueprint)

Execute the given schema blueprint.

Parameters

Blueprint $blueprint

Return Value

void

at line 726
protected void build(Blueprint $blueprint)

Execute the blueprint to build / modify the table.

Parameters

Blueprint $blueprint

Return Value

void

at line 736
protected void executeStatements(array $statements)

Execute the given schema statements in order.

Parameters

array $statements

Return Value

void

at line 748
protected array selectMetadata(string $query)

Read schema metadata from the same write connection that migrations mutate.

Parameters

string $query

Return Value

array

at line 758
protected mixed scalarMetadata(string $query)

Read a scalar result through the metadata execution hook.

Parameters

string $query

Return Value

mixed

Exceptions

MultipleColumnsSelectedException

at line 774
protected bool commandsAreDeclaredOn(Blueprint $blueprint, string $grammar)

Determine whether every executable command is declared by the framework grammar.

Parameters

Blueprint $blueprint
string $grammar

Return Value

bool

at line 792
protected Blueprint createBlueprint(string $table, Closure|null $callback = null)

Create a new command set with a Closure.

Parameters

string $table
Closure|null $callback

Return Value

Blueprint

at line 808
array|null getCurrentSchemaListing()

Get the names of the current schemas for the connection.

Return Value

array|null

at line 816
string|null getCurrentSchemaName()

Get the default schema name for the connection.

Return Value

string|null

at line 828
array parseSchemaAndTable(string $reference, bool|string|null $withDefaultSchema = null)

Parse the given database object reference and extract the schema and table.

Parameters

string $reference
bool|string|null $withDefaultSchema

Return Value

array

Exceptions

InvalidArgumentException

at line 853
Connection getConnection()

Get the database connection instance.

Return Value

Connection

at line 863
void blueprintResolver(Closure $resolver)

Set the Schema Blueprint resolver callback.

Parameters

Closure $resolver

Return Value

void

at line 871
static void flushState()

Flush all static state.

Return Value

void