Blueprint
class Blueprint
Handles schema definitions before executing them.
Properties
| protected | $columns | ||
| protected array | $columnModifiers | ||
| protected | $dbDriver | ||
| protected | $engine | ||
| protected | $foreignKeys | ||
| protected | $indexes | ||
| protected string|null | $lastColumn | ||
| protected | $table |
Methods
Constructor for Blueprint class.
Specifies the position of the last defined column to appear immediately after another column in the table (MySQL only).
Define a big integer column.
Create the table.
Create a foreign key (MySQL only).
Define an index on one or more columns.
Drops a column or group of columns. If a column has a restraint then warnings are presented to the user.
Drops a foreign key constraint from the table (MySQL only).
Drops a table if it exists.
Drops indexed value from the table.
Drops primary key field from the table.
Drops column with unique constraint from the table.
Define a foreign key (MySQL only).
Determines if a particular column has a foreign key constraint (MySQL only).
Add an ID column (primary key).
Define an index.
Tests if a column is a foreign key.
Tests if field is an index. If true then reports to console.
Tests if field is a primary key. If true then reports to console.
Tests if a column has a UNIQUE constraint.
Define a medium integer column.
Renames a particular column
Renames a foreign key.
Renames an indexed column by preserving and reapplying the index.
Renames the table's primary key.
Renames a column with a unique constraint by preserving and reapplying the index.
Sets foreign keys during creating of table or renaming of existing foreign key.
Sets the unique index on a column.
Define a small integer column.
Define a soft delete column.
Define timestamps (created_at and updated_at).
Define a tiny integer column.
Define an unsigned integer column (MySQL only).
Define an unsigned big integer column (MySQL only).
Update an existing table.
Define a UUID column (MySQL only).
Details
at line 28
__construct(string $table)
Constructor for Blueprint class.
at line 48
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;
at line 61
Blueprint
bigInteger(string $name)
Define a big integer column.
at line 73
Blueprint
boolean(string $name)
Define a boolean column.
at line 82
void
create()
Create the table.
at line 109
protected void
createForeignKey(string $fk)
Create a foreign key (MySQL only).
at line 130
protected void
createIndex(array|string $index)
Define an index on one or more columns.
This method registers a standard (non-unique) index to be created
after the table is created. The index will be applied to the given column
or set of columns. The index name is automatically generated as
{table}_{column}_idx for a single column or based on the provided structure.
Note: Actual SQL index creation occurs in the create() method via createIndex().
at line 157
Blueprint
date(string $name)
Define a date column.
at line 169
Blueprint
dateTime(string $name)
Define a datetime column.
at line 183
Blueprint
decimal(string $name, int $precision = 8, int $scale = 2)
Define a decimal column.
at line 203
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.
at line 234
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.
at line 290
void
dropForeign(string $column, bool $preserveColumn = true)
Drops a foreign key constraint from the table (MySQL only).
at line 325
void
dropIfExists(string $table)
Drops a table if it exists.
at line 340
void
dropIndex(string $column, bool $preserveColumn = true)
Drops indexed value from the table.
at line 373
void
dropPrimaryKey(string $column, bool $preserveColumn = true)
Drops primary key field from the table.
at line 405
void
dropUnique(string $column, bool $preserveColumn = false)
Drops column with unique constraint from the table.
at line 476
Blueprint
double(string $name, int $precision = 16, int $scale = 4)
Define a double column.
at line 489
Blueprint
enum(string $name, array $values)
Define an enum column (MySQL only).
at line 508
Blueprint
float(string $name, int $precision = 8, int $scale = 2)
Define a float column.
at line 523
void
foreign(string $column, string $referencedColumn, string $onTable, string $onDelete = 'RESTRICT', string $onUpdate = 'RESTRICT')
Define a foreign key (MySQL only).
at line 545
private object|null
getForeignKey(string $column)
Determines if a particular column has a foreign key constraint (MySQL only).
at line 572
id()
Add an ID column (primary key).
at line 582
void
index(string $column)
Define an index.
at line 594
private bool
isForeignKey(string $column)
Tests if a column is a foreign key.
If true, reports to the console. Helps prevent unsafe renames or drops.
at line 638
private bool
isIndex(string $column)
Tests if field is an index. If true then reports to console.
at line 667
private bool
isPrimaryKey(string $column)
Tests if field is a primary key. If true then reports to console.
at line 699
private bool
isUnique(string $column)
Tests if a column has a UNIQUE constraint.
If true, reports to the console. This helps avoid modifying unique-indexed columns unintentionally during schema changes like dropping or renaming.
at line 743
Blueprint
integer(string $name)
Define an integer column.
at line 756
Blueprint
mediumInteger(string $name)
Define a medium integer column.
at line 767
Blueprint
nullable()
Modifies last column added to the schema and make it nullable.
at line 782
void
renameColumn(string $from, string $to)
Renames a particular column
at line 807
void
renameForeign(string $from, string $to)
Renames a foreign key.
at line 849
void
renameIndex(string $from, string $to)
Renames an indexed column by preserving and reapplying the index.
at line 884
void
renamePrimaryKey(string $from, string $to)
Renames the table's primary key.
at line 919
void
renameUnique(string $from, string $to)
Renames a column with a unique constraint by preserving and reapplying the index.
at line 953
private void
setForeignKeys()
Sets foreign keys during creating of table or renaming of existing foreign key.
at line 970
private void
setUnique(string $column)
Sets the unique index on a column.
at line 985
Blueprint
smallInteger(string $name)
Define a small integer column.
at line 996
Blueprint
softDeletes()
Define a soft delete column.
at line 1008
Blueprint
string(string $name, int $length = 255)
Define a string column.
at line 1021
Blueprint
text(string $name)
Define a text column.
at line 1033
Blueprint
time(string $name)
Define a time column.
at line 1045
Blueprint
timestamp(string $name)
Define a timestamp column.
at line 1054
void
timestamps()
Define timestamps (created_at and updated_at).
at line 1065
Blueprint
tinyInteger(string $name)
Define a tiny integer column.
at line 1078
Blueprint
unique()
Adds a unique index to the last defined column.
at line 1094
Blueprint
unsignedInteger(string $name)
Define an unsigned integer column (MySQL only).
at line 1110
Blueprint
unsignedBigInteger(string $name)
Define an unsigned big integer column (MySQL only).
at line 1124
void
update()
Update an existing table.
at line 1157
uuid(string $name)
Define a UUID column (MySQL only).