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 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;
at line 63
Blueprint
bigInteger(string $name)
Define a big integer column.
at line 75
Blueprint
boolean(string $name)
Define a boolean column.
at line 84
void
create()
Create the table.
at line 111
protected void
createForeignKey(string $fk)
Create a foreign key (MySQL only).
at line 132
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 159
Blueprint
date(string $name)
Define a date column.
at line 171
Blueprint
dateTime(string $name)
Define a datetime column.
at line 185
Blueprint
decimal(string $name, int $precision = 8, int $scale = 2)
Define a decimal column.
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.
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.
at line 292
void
dropForeign(string $column, bool $preserveColumn = true)
Drops a foreign key constraint from the table (MySQL only).
at line 327
void
dropIfExists(string $table)
Drops a table if it exists.
at line 342
void
dropIndex(string $column, bool $preserveColumn = true)
Drops indexed value from the table.
at line 375
void
dropPrimaryKey(string $column, bool $preserveColumn = true)
Drops primary key field from the table.
at line 407
void
dropUnique(string $column, bool $preserveColumn = false)
Drops column with unique constraint from the table.
at line 478
Blueprint
double(string $name, int $precision = 16, int $scale = 4)
Define a double column.
at line 491
Blueprint
enum(string $name, array $values)
Define an enum column (MySQL only).
at line 510
Blueprint
float(string $name, int $precision = 8, int $scale = 2)
Define a float column.
at line 525
void
foreign(string $column, string $referencedColumn, string $onTable, string $onDelete = 'RESTRICT', string $onUpdate = 'RESTRICT')
Define a foreign key (MySQL only).
at line 547
private object|null
getForeignKey(string $column)
Determines if a particular column has a foreign key constraint (MySQL only).
at line 574
id()
Add an ID column (primary key).
at line 584
void
index(string $column)
Define an index.
at line 596
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 640
private bool
isIndex(string $column)
Tests if field is an index. If true then reports to console.
at line 669
private bool
isPrimaryKey(string $column)
Tests if field is a primary key. If true then reports to console.
at line 701
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 745
Blueprint
integer(string $name)
Define an integer column.
at line 758
Blueprint
mediumInteger(string $name)
Define a medium integer column.
at line 769
Blueprint
nullable()
Modifies last column added to the schema and make it nullable.
at line 784
void
renameColumn(string $from, string $to)
Renames a particular column
at line 809
void
renameForeign(string $from, string $to)
Renames a foreign key.
at line 851
void
renameIndex(string $from, string $to)
Renames an indexed column by preserving and reapplying the index.
at line 886
void
renamePrimaryKey(string $from, string $to)
Renames the table's primary key.
at line 921
void
renameUnique(string $from, string $to)
Renames a column with a unique constraint by preserving and reapplying the index.
at line 955
private void
setForeignKeys()
Sets foreign keys during creating of table or renaming of existing foreign key.
at line 972
private void
setUnique(string $column)
Sets the unique index on a column.
at line 987
Blueprint
smallInteger(string $name)
Define a small integer column.
at line 998
Blueprint
softDeletes()
Define a soft delete column.
at line 1010
Blueprint
string(string $name, int $length = 255)
Define a string column.
at line 1023
Blueprint
text(string $name)
Define a text column.
at line 1035
Blueprint
time(string $name)
Define a time column.
at line 1047
Blueprint
timestamp(string $name)
Define a timestamp column.
at line 1056
void
timestamps()
Define timestamps (created_at and updated_at).
at line 1067
Blueprint
tinyInteger(string $name)
Define a tiny integer column.
at line 1080
Blueprint
unique()
Adds a unique index to the last defined column.
at line 1096
Blueprint
unsignedInteger(string $name)
Define an unsigned integer column (MySQL only).
at line 1112
Blueprint
unsignedBigInteger(string $name)
Define an unsigned big integer column (MySQL only).
at line 1126
void
update()
Update an existing table.
at line 1159
uuid(string $name)
Define a UUID column (MySQL only).