class Builder (View source)

Properties

protected Connection $connection

The database connection instance.

protected Grammar $grammar

The schema grammar instance.

protected Closure $resolver

The Blueprint resolver callback.

static int|null $defaultStringLength

The default string length for migrations.

static string $defaultMorphKeyType

The default relationship morph key type.

static bool $alwaysUsesNativeSchemaOperationsIfPossible

Indicates whether Doctrine DBAL usage will be prevented if possible when dropping, renaming, and modifying columns.

Methods

void
__construct(Connection $connection)

Create a new database Schema manager.

static void
defaultStringLength(int $length)

Set the default string length 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.

static void
useNativeSchemaOperationsIfPossible(bool $value = true)

Attempt to use native schema operations for dropping, renaming, and modifying columns, even if Doctrine DBAL is installed.

bool
createDatabase(string $name)

Create a database in the schema.

bool
dropDatabaseIfExists(string $name)

Drop a database from the schema if the database exists.

bool
hasTable(string $table)

Determine if the given table exists.

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.

string
getColumnType(string $table, string $column)

Get the data type for the given column name.

array
getColumnListing(string $table)

Get the column listing 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
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, string|array $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.

array
getAllTables()

Get all of the table names for the database.

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.

void
build(Blueprint $blueprint)

Execute the blueprint to build / modify the table.

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

Create a new command set with a Closure.

getConnection()

Get the database connection instance.

$this
setConnection(Connection $connection)

Set the database connection instance.

void
blueprintResolver(Closure $resolver)

Set the Schema Blueprint resolver callback.

Details

void __construct(Connection $connection)

Create a new database Schema manager.

Parameters

Connection $connection

Return Value

void

static void defaultStringLength(int $length)

Set the default string length for migrations.

Parameters

int $length

Return Value

void

static void defaultMorphKeyType(string $type)

Set the default morph key type for migrations.

Parameters

string $type

Return Value

void

Exceptions

InvalidArgumentException

static void morphUsingUuids()

Set the default morph key type for migrations to UUIDs.

Return Value

void

static void morphUsingUlids()

Set the default morph key type for migrations to ULIDs.

Return Value

void

static void useNativeSchemaOperationsIfPossible(bool $value = true)

Attempt to use native schema operations for dropping, renaming, and modifying columns, even if Doctrine DBAL is installed.

Parameters

bool $value

Return Value

void

bool createDatabase(string $name)

Create a database in the schema.

Parameters

string $name

Return Value

bool

Exceptions

LogicException

bool dropDatabaseIfExists(string $name)

Drop a database from the schema if the database exists.

Parameters

string $name

Return Value

bool

Exceptions

LogicException

bool hasTable(string $table)

Determine if the given table exists.

Parameters

string $table

Return Value

bool

bool hasColumn(string $table, string $column)

Determine if the given table has a given column.

Parameters

string $table
string $column

Return Value

bool

bool hasColumns(string $table, array $columns)

Determine if the given table has given columns.

Parameters

string $table
array $columns

Return Value

bool

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

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

string getColumnType(string $table, string $column)

Get the data type for the given column name.

Parameters

string $table
string $column

Return Value

string

array getColumnListing(string $table)

Get the column listing for a given table.

Parameters

string $table

Return Value

array

void table(string $table, Closure $callback)

Modify a table on the schema.

Parameters

string $table
Closure $callback

Return Value

void

void create(string $table, Closure $callback)

Create a new table on the schema.

Parameters

string $table
Closure $callback

Return Value

void

void drop(string $table)

Drop a table from the schema.

Parameters

string $table

Return Value

void

void dropIfExists(string $table)

Drop a table from the schema if it exists.

Parameters

string $table

Return Value

void

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

Drop columns from a table schema.

Parameters

string $table
string|array $columns

Return Value

void

void dropAllTables()

Drop all tables from the database.

Return Value

void

Exceptions

LogicException

void dropAllViews()

Drop all views from the database.

Return Value

void

Exceptions

LogicException

void dropAllTypes()

Drop all types from the database.

Return Value

void

Exceptions

LogicException

array getAllTables()

Get all of the table names for the database.

Return Value

array

Exceptions

LogicException

void rename(string $from, string $to)

Rename a table on the schema.

Parameters

string $from
string $to

Return Value

void

bool enableForeignKeyConstraints()

Enable foreign key constraints.

Return Value

bool

bool disableForeignKeyConstraints()

Disable foreign key constraints.

Return Value

bool

mixed withoutForeignKeyConstraints(Closure $callback)

Disable foreign key constraints during the execution of a callback.

Parameters

Closure $callback

Return Value

mixed

protected void build(Blueprint $blueprint)

Execute the blueprint to build / modify the table.

Parameters

Blueprint $blueprint

Return Value

void

protected Blueprint createBlueprint(string $table, Closure $callback = null)

Create a new command set with a Closure.

Parameters

string $table
Closure $callback

Return Value

Blueprint

Connection getConnection()

Get the database connection instance.

Return Value

Connection

$this setConnection(Connection $connection)

Set the database connection instance.

Parameters

Connection $connection

Return Value

$this

void blueprintResolver(Closure $resolver)

Set the Schema Blueprint resolver callback.

Parameters

Closure $resolver

Return Value

void