Blueprint
class Blueprint (View source)
Traits
Properties
static protected array | $macros | The registered string macros. |
from Macroable |
protected | $connection | The database connection instance. |
|
protected | $grammar | The schema grammar instance. |
|
protected string | $table | The table the blueprint describes. |
|
protected ColumnDefinition[] | $columns | The columns that should be added to the table. |
|
protected Fluent[] | $commands | The commands that should be run for the table. |
|
string | $engine | The storage engine that should be used for the table. |
|
string | $charset | The default character set that should be used for the table. |
|
string | $collation | The collation that should be used for the table. |
|
bool | $temporary | Whether to make the table temporary. |
|
string | $after | The column to add new columns after. |
|
protected BlueprintState|null | $state | The blueprint state instance. |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new schema blueprint.
Execute the blueprint against the database.
Get the raw SQL statements for the blueprint.
Ensure the commands on the blueprint are valid for the connection type.
Add the commands that are implied by the blueprint's state.
Add the index commands fluently specified on columns.
Add the fluent commands specified on any columns.
Add the alter commands if whenever needed.
Determine if the blueprint has a create command.
Specify the storage engine that should be used for the table.
Specify that the InnoDB storage engine should be used for the table (MySQL only).
Specify the character set that should be used for the table.
Specify the collation that should be used for the table.
Indicate that the table needs to be temporary.
Indicate that the table should be dropped if it exists.
Indicate that the given columns should be dropped.
Indicate that the given columns should be renamed.
Indicate that the given primary key should be dropped.
Indicate that the given unique key should be dropped.
Indicate that the given fulltext index should be dropped.
Indicate that the given spatial index should be dropped.
Indicate that the given foreign key should be dropped.
Indicate that the given column and foreign key should be dropped.
Indicate that the given foreign key should be dropped.
Indicate that the given foreign key should be dropped.
Indicate that the given indexes should be renamed.
Indicate that the timestamp columns should be dropped.
Indicate that the timestamp columns should be dropped.
Indicate that the soft delete column should be dropped.
Indicate that the soft delete column should be dropped.
Indicate that the remember token column should be dropped.
Indicate that the polymorphic columns should be dropped.
Specify the primary key(s) for the table.
Specify a unique index for the table.
Specify an index for the table.
Specify a fulltext index for the table.
Specify a spatial index for the table.
Specify a raw index for the table.
Specify a foreign key for the table.
Create a new auto-incrementing big integer (8-byte) column on the table.
Create a new auto-incrementing integer (4-byte) column on the table.
Create a new auto-incrementing integer (4-byte) column on the table.
Create a new auto-incrementing tiny integer (1-byte) column on the table.
Create a new auto-incrementing small integer (2-byte) column on the table.
Create a new auto-incrementing medium integer (3-byte) column on the table.
Create a new auto-incrementing big integer (8-byte) column on the table.
Create a new char column on the table.
Create a new string column on the table.
Create a new tiny text column on the table.
Create a new text column on the table.
Create a new medium text column on the table.
Create a new long text column on the table.
Create a new integer (4-byte) column on the table.
Create a new tiny integer (1-byte) column on the table.
Create a new small integer (2-byte) column on the table.
Create a new medium integer (3-byte) column on the table.
Create a new big integer (8-byte) column on the table.
Create a new unsigned integer (4-byte) column on the table.
Create a new unsigned tiny integer (1-byte) column on the table.
Create a new unsigned small integer (2-byte) column on the table.
Create a new unsigned medium integer (3-byte) column on the table.
Create a new unsigned big integer (8-byte) column on the table.
Create a new unsigned big integer (8-byte) column on the table.
Create a foreign ID column for the given model.
Create a new float column on the table.
Create a new double column on the table.
Create a new decimal column on the table.
Create a new boolean column on the table.
Create a new enum column on the table.
Create a new set column on the table.
Create a new json column on the table.
Create a new jsonb column on the table.
Create a new date column on the table.
Create a new date-time column on the table.
Create a new date-time column (with time zone) on the table.
Create a new time column on the table.
Create a new time column (with time zone) on the table.
Create a new timestamp column on the table.
Create a new timestamp (with time zone) column on the table.
Add nullable creation and update timestamps to the table.
Add nullable creation and update timestamps to the table.
Add creation and update timestampTz columns to the table.
Add creation and update datetime columns to the table.
Add a "deleted at" timestamp for the table.
Add a "deleted at" timestampTz for the table.
Add a "deleted at" datetime column to the table.
Create a new year column on the table.
Create a new binary column on the table.
Create a new UUID column on the table.
Create a new UUID column on the table with a foreign key constraint.
Create a new ULID column on the table.
Create a new ULID column on the table with a foreign key constraint.
Create a new IP address column on the table.
Create a new MAC address column on the table.
Create a new geometry column on the table.
Create a new geography column on the table.
Create a new generated, computed column on the table.
Create a new vector column on the table.
Add the proper columns for a polymorphic table.
Add nullable columns for a polymorphic table.
Add the proper columns for a polymorphic table using numeric IDs (incremental).
Add nullable columns for a polymorphic table using numeric IDs (incremental).
Add the proper columns for a polymorphic table using UUIDs.
Add nullable columns for a polymorphic table using UUIDs.
Add the proper columns for a polymorphic table using ULIDs.
Add nullable columns for a polymorphic table using ULIDs.
Add the remember_token
column to the table.
Create a new custom column on the table.
Add a new index command to the blueprint.
Create a new drop index command on the blueprint.
Create a default index name for the table.
Add a new column to the blueprint.
Remove a column from the schema blueprint.
Add a new command to the blueprint.
Create a new Fluent command.
Get the table the blueprint describes.
Get the columns on the blueprint.
Get the commands on the blueprint.
Get the state of the blueprint.
Get the columns on the blueprint that should be added.
Get the default time precision.
Details
__construct(Connection $connection, string $table, Closure|null $callback = null)
Create a new schema blueprint.
protected void
ensureCommandsAreValid()
Ensure the commands on the blueprint are valid for the connection type.
protected Collection
commandsNamed(array $names)
deprecated
deprecated Will be removed in a future Laravel version.
Get all of the commands matching the given names.
Fluent
dropPrimary(string|array|null $index = null)
Indicate that the given primary key should be dropped.
Fluent
dropSpatialIndex(string|array $index)
Indicate that the given spatial index should be dropped.
Fluent
dropConstrainedForeignId(string $column)
Indicate that the given column and foreign key should be dropped.
Fluent
dropForeignIdFor(Model|string $model, string|null $column = null)
Indicate that the given foreign key should be dropped.
Fluent
dropConstrainedForeignIdFor(Model|string $model, string|null $column = null)
Indicate that the given foreign key should be dropped.
void
dropSoftDeletes(string $column = 'deleted_at')
Indicate that the soft delete column should be dropped.
void
dropSoftDeletesTz(string $column = 'deleted_at')
Indicate that the soft delete column should be dropped.
void
dropMorphs(string $name, string|null $indexName = null)
Indicate that the polymorphic columns should be dropped.
IndexDefinition
primary(string|array $columns, string|null $name = null, string|null $algorithm = null)
Specify the primary key(s) for the table.
IndexDefinition
unique(string|array $columns, string|null $name = null, string|null $algorithm = null)
Specify a unique index for the table.
IndexDefinition
index(string|array $columns, string|null $name = null, string|null $algorithm = null)
Specify an index for the table.
IndexDefinition
fullText(string|array $columns, string|null $name = null, string|null $algorithm = null)
Specify a fulltext index for the table.
IndexDefinition
spatialIndex(string|array $columns, string|null $name = null)
Specify a spatial index for the table.
ForeignKeyDefinition
foreign(string|array $columns, string|null $name = null)
Specify a foreign key for the table.
ColumnDefinition
id(string $column = 'id')
Create a new auto-incrementing big integer (8-byte) column on the table.
ColumnDefinition
increments(string $column)
Create a new auto-incrementing integer (4-byte) column on the table.
ColumnDefinition
integerIncrements(string $column)
Create a new auto-incrementing integer (4-byte) column on the table.
ColumnDefinition
tinyIncrements(string $column)
Create a new auto-incrementing tiny integer (1-byte) column on the table.
ColumnDefinition
smallIncrements(string $column)
Create a new auto-incrementing small integer (2-byte) column on the table.
ColumnDefinition
mediumIncrements(string $column)
Create a new auto-incrementing medium integer (3-byte) column on the table.
ColumnDefinition
bigIncrements(string $column)
Create a new auto-incrementing big integer (8-byte) column on the table.
ColumnDefinition
char(string $column, int|null $length = null)
Create a new char column on the table.
ColumnDefinition
string(string $column, int|null $length = null)
Create a new string column on the table.
ColumnDefinition
integer(string $column, bool $autoIncrement = false, bool $unsigned = false)
Create a new integer (4-byte) column on the table.
ColumnDefinition
tinyInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)
Create a new tiny integer (1-byte) column on the table.
ColumnDefinition
smallInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)
Create a new small integer (2-byte) column on the table.
ColumnDefinition
mediumInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)
Create a new medium integer (3-byte) column on the table.
ColumnDefinition
bigInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)
Create a new big integer (8-byte) column on the table.
ColumnDefinition
unsignedInteger(string $column, bool $autoIncrement = false)
Create a new unsigned integer (4-byte) column on the table.
ColumnDefinition
unsignedTinyInteger(string $column, bool $autoIncrement = false)
Create a new unsigned tiny integer (1-byte) column on the table.
ColumnDefinition
unsignedSmallInteger(string $column, bool $autoIncrement = false)
Create a new unsigned small integer (2-byte) column on the table.
ColumnDefinition
unsignedMediumInteger(string $column, bool $autoIncrement = false)
Create a new unsigned medium integer (3-byte) column on the table.
ColumnDefinition
unsignedBigInteger(string $column, bool $autoIncrement = false)
Create a new unsigned big integer (8-byte) column on the table.
ForeignIdColumnDefinition
foreignId(string $column)
Create a new unsigned big integer (8-byte) column on the table.
ForeignIdColumnDefinition
foreignIdFor(Model|string $model, string|null $column = null)
Create a foreign ID column for the given model.
ColumnDefinition
decimal(string $column, int $total = 8, int $places = 2)
Create a new decimal column on the table.
ColumnDefinition
dateTime(string $column, int|null $precision = null)
Create a new date-time column on the table.
ColumnDefinition
dateTimeTz(string $column, int|null $precision = null)
Create a new date-time column (with time zone) on the table.
ColumnDefinition
time(string $column, int|null $precision = null)
Create a new time column on the table.
ColumnDefinition
timeTz(string $column, int|null $precision = null)
Create a new time column (with time zone) on the table.
ColumnDefinition
timestamp(string $column, int|null $precision = null)
Create a new timestamp column on the table.
ColumnDefinition
timestampTz(string $column, int|null $precision = null)
Create a new timestamp (with time zone) column on the table.
void
timestamps(int|null $precision = null)
Add nullable creation and update timestamps to the table.
void
nullableTimestamps(int|null $precision = null)
Add nullable creation and update timestamps to the table.
Alias for self::timestamps().
void
timestampsTz(int|null $precision = null)
Add creation and update timestampTz columns to the table.
ColumnDefinition
softDeletes(string $column = 'deleted_at', int|null $precision = null)
Add a "deleted at" timestamp for the table.
ColumnDefinition
softDeletesTz(string $column = 'deleted_at', int|null $precision = null)
Add a "deleted at" timestampTz for the table.
ColumnDefinition
softDeletesDatetime(string $column = 'deleted_at', int|null $precision = null)
Add a "deleted at" datetime column to the table.
ColumnDefinition
binary(string $column, int|null $length = null, bool $fixed = false)
Create a new binary column on the table.
ForeignIdColumnDefinition
foreignUuid(string $column)
Create a new UUID column on the table with a foreign key constraint.
ColumnDefinition
ulid(string $column = 'ulid', int|null $length = 26)
Create a new ULID column on the table.
ForeignIdColumnDefinition
foreignUlid(string $column, int|null $length = 26)
Create a new ULID column on the table with a foreign key constraint.
ColumnDefinition
ipAddress(string $column = 'ip_address')
Create a new IP address column on the table.
ColumnDefinition
macAddress(string $column = 'mac_address')
Create a new MAC address column on the table.
ColumnDefinition
geometry(string $column, string|null $subtype = null, int $srid = 0)
Create a new geometry column on the table.
ColumnDefinition
geography(string $column, string|null $subtype = null, int $srid = 4326)
Create a new geography column on the table.
ColumnDefinition
computed(string $column, string $expression)
Create a new generated, computed column on the table.
ColumnDefinition
vector(string $column, int|null $dimensions = null)
Create a new vector column on the table.
void
morphs(string $name, string|null $indexName = null)
Add the proper columns for a polymorphic table.
void
nullableMorphs(string $name, string|null $indexName = null)
Add nullable columns for a polymorphic table.
void
numericMorphs(string $name, string|null $indexName = null)
Add the proper columns for a polymorphic table using numeric IDs (incremental).
void
nullableNumericMorphs(string $name, string|null $indexName = null)
Add nullable columns for a polymorphic table using numeric IDs (incremental).
void
uuidMorphs(string $name, string|null $indexName = null)
Add the proper columns for a polymorphic table using UUIDs.
void
nullableUuidMorphs(string $name, string|null $indexName = null)
Add nullable columns for a polymorphic table using UUIDs.
void
ulidMorphs(string $name, string|null $indexName = null)
Add the proper columns for a polymorphic table using ULIDs.
void
nullableUlidMorphs(string $name, string|null $indexName = null)
Add nullable columns for a polymorphic table using ULIDs.
ColumnDefinition
rawColumn(string $column, string $definition)
Create a new custom column on the table.
protected Fluent
indexCommand(string $type, string|array $columns, string $index, string|null $algorithm = null)
Add a new index command to the blueprint.
protected Fluent
dropIndexCommand(string $command, string $type, string|array $index)
Create a new drop index command on the blueprint.
protected string
createIndexName(string $type, array $columns)
Create a default index name for the table.
ColumnDefinition
addColumn(string $type, string $name, array $parameters = [])
Add a new column to the blueprint.
protected ColumnDefinition
addColumnDefinition(ColumnDefinition $definition)
Add a new column definition to the blueprint.
void
after(string $column, Closure $callback)
Add the columns from the callback after the given column.
protected Fluent
addCommand(string $name, array $parameters = [])
Add a new command to the blueprint.
ColumnDefinition[]
getChangedColumns()
deprecated
deprecated Will be removed in a future Laravel version.
Get the columns on the blueprint that should be changed.