class Blueprint

Handles schema definitions before executing them.

Methods

__construct(string $table)

Constructor for Blueprint class.

after(string $column)

Specifies the position of the last defined column to appear immediately after another column in the table (MySQL only).

bigInteger(string $name)

Define a big integer column.

boolean(string $name)

Define a boolean column.

void
create()

Create the table.

date(string $name)

Define a date column.

dateTime(string $name)

Define a datetime column.

decimal(string $name, int $precision = 8, int $scale = 2)

Define a decimal column.

default(string|int|float|bool $value)

Adds a DEFAULT value to the last defined column.

void
dropColumns(array|string $columns)

Drops a column or group of columns. If a column has a restraint then warnings are presented to the user.

void
dropForeign(string $column, bool $preserveColumn = true)

Drops a foreign key constraint from the table (MySQL only).

void
dropIfExists(string $table)

Drops a table if it exists.

void
dropIndex(string $column, bool $preserveColumn = true)

Drops indexed value from the table.

void
dropPrimaryKey(string $column, bool $preserveColumn = true)

Drops primary key field from the table.

void
dropUnique(string $column, bool $preserveColumn = false)

Drops column with unique constraint from the table.

double(string $name, int $precision = 16, int $scale = 4)

Define a double column.

enum(string $name, array $values)

Define an enum column (MySQL only).

float(string $name, int $precision = 8, int $scale = 2)

Define a float column.

void
foreign(string $column, string $referencedColumn, string $onTable, string $onDelete = 'RESTRICT', string $onUpdate = 'RESTRICT')

Define a foreign key (MySQL only).

id()

Add an ID column (primary key).

void
index(string $column)

Define an index.

integer(string $name)

Define an integer column.

mediumInteger(string $name)

Define a medium integer column.

nullable()

Modifies last column added to the schema and make it nullable.

void
renameColumn(string $from, string $to)

Renames a particular column

void
renameForeign(string $from, string $to)

Renames a foreign key.

void
renameIndex(string $from, string $to)

Renames an indexed column by preserving and reapplying the index.

void
renamePrimaryKey(string $from, string $to)

Renames the table's primary key.

void
renameUnique(string $from, string $to)

Renames a column with a unique constraint by preserving and reapplying the index.

smallInteger(string $name)

Define a small integer column.

softDeletes()

Define a soft delete column.

string(string $name, int $length = 255)

Define a string column.

text(string $name)

Define a text column.

time(string $name)

Define a time column.

timestamp(string $name)

Define a timestamp column.

void
timestamps()

Define timestamps (created_at and updated_at).

tinyInteger(string $name)

Define a tiny integer column.

unique()

Adds a unique index to the last defined column.

unsignedInteger(string $name)

Define an unsigned integer column (MySQL only).

unsignedBigInteger(string $name)

Define an unsigned big integer column (MySQL only).

void
update()

Update an existing table.

uuid(string $name)

Define a UUID column (MySQL only).

Details

at line 30
__construct(string $table)

Constructor for Blueprint class.

Parameters

string $table

The name of the table to be modified.

at line 50
Blueprint after(string $column)

Specifies the position of the last defined column to appear immediately after another column in the table (MySQL only).

This method is only meaningful during ALTER TABLE operations (i.e., when calling $table->update()). The generated SQL will include an AFTER column_name clause to control column order.

Example: $table->string('nickname')->after('last_name'); // Produces: ALTER TABLE users ADD COLUMN nickname VARCHAR(255) AFTER last_name;

Parameters

string $column

The existing column name after which the new column should be added.

Return Value

Blueprint

Returns the current Blueprint instance for method chaining.

at line 63
Blueprint bigInteger(string $name)

Define a big integer column.

Parameters

string $name

The name of the column to be created as BIGINT.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 75
Blueprint boolean(string $name)

Define a boolean column.

Parameters

string $name

The name of the column to be created as TINYINT(1).

Return Value

Blueprint

Return the instance to allow method chaining.

at line 84
void create()

Create the table.

Return Value

void

at line 159
Blueprint date(string $name)

Define a date column.

Parameters

string $name

The name of the column to be created as DATE.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 171
Blueprint dateTime(string $name)

Define a datetime column.

Parameters

string $name

The name of the column to be created as DATETIME.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 185
Blueprint decimal(string $name, int $precision = 8, int $scale = 2)

Define a decimal column.

Parameters

string $name

The name of the column.

int $precision

Total number of digits.

int $scale

Number of digits after the decimal.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 205
Blueprint default(string|int|float|bool $value)

Adds a DEFAULT value to the last defined column.

This method appends a default value to the most recently added column in the schema definition. It supports string, integer, float, and boolean values. If no columns have been added yet, it throws an exception. In SQLite, default values for certain column types like TEXT and BLOB are skipped.

Parameters

string|int|float|bool $value

The default value to assign to the last defined column. Strings will be wrapped in quotes. Other types will be cast directly.

Return Value

Blueprint

Returns the current Blueprint instance for method chaining.

Exceptions

Exception

at line 236
void dropColumns(array|string $columns)

Drops a column or group of columns. If a column has a restraint then warnings are presented to the user.

Parameters

array|string $columns

An individual column or an array of columns to drop.

Return Value

void

at line 292
void dropForeign(string $column, bool $preserveColumn = true)

Drops a foreign key constraint from the table (MySQL only).

Parameters

string $column

The name of the column to be dropped.

bool $preserveColumn

When true only the foreign key constraint is removed. If set to false the column is also dropped from the table. The default value is true.

Return Value

void

at line 327
void dropIfExists(string $table)

Drops a table if it exists.

Parameters

string $table

The name of the table to drop if it exists.

Return Value

void

at line 342
void dropIndex(string $column, bool $preserveColumn = true)

Drops indexed value from the table.

Parameters

string $column

The name of the column to be dropped.

bool $preserveColumn

When true only the index constraint is removed. If set to false the column is also dropped from the table. The default value is true.

Return Value

void

at line 375
void dropPrimaryKey(string $column, bool $preserveColumn = true)

Drops primary key field from the table.

Parameters

string $column

The name of the column to be dropped.

bool $preserveColumn

When true only the primary key constraint is removed. If set to false the column is also dropped from the table. The default value is true.

Return Value

void

at line 407
void dropUnique(string $column, bool $preserveColumn = false)

Drops column with unique constraint from the table.

Parameters

string $column

The name of the column to be dropped.

bool $preserveColumn

When true only the unique constraint is removed. If set to false the column is also dropped from the table. The default value is true.

Return Value

void

at line 478
Blueprint double(string $name, int $precision = 16, int $scale = 4)

Define a double column.

Parameters

string $name

The name of the column to be created as DOUBLE.

int $precision

Total number of digits.

int $scale

Number of digits after the decimal.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 491
Blueprint enum(string $name, array $values)

Define an enum column (MySQL only).

Parameters

string $name

The name of the enum column.

array $values

An array of allowed values for the ENUM.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 510
Blueprint float(string $name, int $precision = 8, int $scale = 2)

Define a float column.

Parameters

string $name

The name of the column to be created as FLOAT.

int $precision

Total number of digits.

int $scale

Number of digits after the decimal.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 525
void foreign(string $column, string $referencedColumn, string $onTable, string $onDelete = 'RESTRICT', string $onUpdate = 'RESTRICT')

Define a foreign key (MySQL only).

Parameters

string $column

The column name to add a foreign key constraint on.

string $referencedColumn
string $onTable

The name of the table being referenced.

string $onDelete

Action on delete (e.g., CASCADE).

string $onUpdate

Action on update (e.g., CASCADE).

Return Value

void

at line 574
id()

Add an ID column (primary key).

at line 584
void index(string $column)

Define an index.

Parameters

string $column

The column name to add an index on.

Return Value

void

at line 745
Blueprint integer(string $name)

Define an integer column.

Parameters

string $name

The name of the column to be created as INT.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 758
Blueprint mediumInteger(string $name)

Define a medium integer column.

Parameters

string $name

The name of the column to be created as MEDIUMINT.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 769
Blueprint nullable()

Modifies last column added to the schema and make it nullable.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 784
void renameColumn(string $from, string $to)

Renames a particular column

Parameters

string $from

The column's original name.

string $to

The column's new name.

Return Value

void

at line 809
void renameForeign(string $from, string $to)

Renames a foreign key.

Parameters

string $from

The original column name.

string $to

The new column name.

Return Value

void

at line 851
void renameIndex(string $from, string $to)

Renames an indexed column by preserving and reapplying the index.

Parameters

string $from

The original column name.

string $to

The new column name.

Return Value

void

at line 886
void renamePrimaryKey(string $from, string $to)

Renames the table's primary key.

Parameters

string $from

The original column name.

string $to

The new column name.

Return Value

void

at line 921
void renameUnique(string $from, string $to)

Renames a column with a unique constraint by preserving and reapplying the index.

Parameters

string $from

The original column name.

string $to

The new column name.

Return Value

void

at line 987
Blueprint smallInteger(string $name)

Define a small integer column.

Parameters

string $name

The name of the column to be created as SMALLINT.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 998
Blueprint softDeletes()

Define a soft delete column.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 1010
Blueprint string(string $name, int $length = 255)

Define a string column.

Parameters

string $name

The name of the column.

int $length

The maximum length of the string column.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 1023
Blueprint text(string $name)

Define a text column.

Parameters

string $name

The name of the column to be created as TEXT.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 1035
Blueprint time(string $name)

Define a time column.

Parameters

string $name

The name of the column to be created as TIME.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 1047
Blueprint timestamp(string $name)

Define a timestamp column.

Parameters

string $name

The name of the column to be created as TIMESTAMP.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 1056
void timestamps()

Define timestamps (created_at and updated_at).

Return Value

void

at line 1067
Blueprint tinyInteger(string $name)

Define a tiny integer column.

Parameters

string $name

The name of the column to be created as TINYINT or INTEGER depending on DB driver.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 1080
Blueprint unique()

Adds a unique index to the last defined column.

Return Value

Blueprint

Exceptions

Exception

at line 1096
Blueprint unsignedInteger(string $name)

Define an unsigned integer column (MySQL only).

Parameters

string $name

The name of the column to be created as unsigned INT (MySQL) or INTEGER.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 1112
Blueprint unsignedBigInteger(string $name)

Define an unsigned big integer column (MySQL only).

Parameters

string $name

The name of the column to be created as unsigned BIGINT (MySQL) or INTEGER for SQLite.

Return Value

Blueprint

Return the instance to allow method chaining.

at line 1126
void update()

Update an existing table.

Return Value

void

at line 1158
uuid(string $name)

Define a UUID column (MySQL only).

Parameters

string $name

The name of the column to be created as UUID.