class Blueprint (View source)

Traits

Properties

string $engine The storage engine that should be used for the table.
$charset The default character set that should be used for the table.
$collation The collation that should be used for the table.
bool $temporary Whether to make the table temporary.

Methods

static void
macro(string $name, callable $macro)

Register a custom macro.

from Macroable
static bool
hasMacro(string $name)

Checks if macro is registered.

from Macroable
static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
void
__construct(string $table, Closure $callback = null)

Create a new schema blueprint.

void
build(Connection $connection, Grammar $grammar)

Execute the blueprint against the database.

array
toSql(Connection $connection, Grammar $grammar)

Get the raw SQL statements for the blueprint.

create()

Indicate that the table needs to be created.

void
temporary()

Indicate that the table needs to be temporary.

drop()

Indicate that the table should be dropped.

dropIfExists()

Indicate that the table should be dropped if it exists.

dropColumn(array|mixed $columns)

Indicate that the given columns should be dropped.

renameColumn(string $from, string $to)

Indicate that the given columns should be renamed.

dropPrimary(string|array $index = null)

Indicate that the given primary key should be dropped.

dropUnique(string|array $index)

Indicate that the given unique key should be dropped.

dropIndex(string|array $index)

Indicate that the given index should be dropped.

dropForeign(string|array $index)

Indicate that the given foreign key should be dropped.

void
dropTimestamps()

Indicate that the timestamp columns should be dropped.

void
dropTimestampsTz()

Indicate that the timestamp columns should be dropped.

void
dropSoftDeletes()

Indicate that the soft delete column should be dropped.

void
dropSoftDeletesTz()

Indicate that the soft delete column should be dropped.

void
dropRememberToken()

Indicate that the remember token column should be dropped.

rename(string $to)

Rename the table to a given name.

primary(string|array $columns, string $name = null, string|null $algorithm = null)

Specify the primary key(s) for the table.

unique(string|array $columns, string $name = null, string|null $algorithm = null)

Specify a unique index for the table.

index(string|array $columns, string $name = null, string|null $algorithm = null)

Specify an index for the table.

foreign(string|array $columns, string $name = null)

Specify a foreign key for the table.

increments(string $column)

Create a new auto-incrementing integer (4-byte) column on the table.

tinyIncrements(string $column)

Create a new auto-incrementing tiny integer (1-byte) column on the table.

smallIncrements(string $column)

Create a new auto-incrementing small integer (2-byte) column on the table.

mediumIncrements(string $column)

Create a new auto-incrementing medium integer (3-byte) column on the table.

bigIncrements(string $column)

Create a new auto-incrementing big integer (8-byte) column on the table.

char(string $column, int $length = null)

Create a new char column on the table.

string(string $column, int $length = null)

Create a new string column on the table.

text(string $column)

Create a new text column on the table.

mediumText(string $column)

Create a new medium text column on the table.

longText(string $column)

Create a new long text column on the table.

integer(string $column, bool $autoIncrement = false, bool $unsigned = false)

Create a new integer (4-byte) column on the table.

tinyInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)

Create a new tiny integer (1-byte) column on the table.

smallInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)

Create a new small integer (2-byte) column on the table.

mediumInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)

Create a new medium integer (3-byte) column on the table.

bigInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)

Create a new big integer (8-byte) column on the table.

unsignedInteger(string $column, bool $autoIncrement = false)

Create a new unsigned integer (4-byte) column on the table.

unsignedTinyInteger(string $column, bool $autoIncrement = false)

Create a new unsigned tiny integer (1-byte) column on the table.

unsignedSmallInteger(string $column, bool $autoIncrement = false)

Create a new unsigned small integer (2-byte) column on the table.

unsignedMediumInteger(string $column, bool $autoIncrement = false)

Create a new unsigned medium integer (3-byte) column on the table.

unsignedBigInteger(string $column, bool $autoIncrement = false)

Create a new unsigned big integer (8-byte) column on the table.

float(string $column, int $total = 8, int $places = 2)

Create a new float column on the table.

double(string $column, int|null $total = null, int|null $places = null)

Create a new double column on the table.

decimal(string $column, int $total = 8, int $places = 2)

Create a new decimal column on the table.

boolean(string $column)

Create a new boolean column on the table.

enum(string $column, array $allowed)

Create a new enum column on the table.

json(string $column)

Create a new json column on the table.

jsonb(string $column)

Create a new jsonb column on the table.

date(string $column)

Create a new date column on the table.

dateTime(string $column)

Create a new date-time column on the table.

dateTimeTz(string $column)

Create a new date-time column (with time zone) on the table.

time(string $column)

Create a new time column on the table.

timeTz(string $column)

Create a new time column (with time zone) on the table.

timestamp(string $column)

Create a new timestamp column on the table.

timestampTz(string $column)

Create a new timestamp (with time zone) column on the table.

void
timestamps()

Add nullable creation and update timestamps to the table.

void
nullableTimestamps()

Add nullable creation and update timestamps to the table.

void
timestampsTz()

Add creation and update timestampTz columns to the table.

softDeletes(string $column = 'deleted_at')

Add a "deleted at" timestamp for the table.

softDeletesTz()

Add a "deleted at" timestampTz for the table.

binary(string $column)

Create a new binary column on the table.

uuid(string $column)

Create a new uuid column on the table.

ipAddress(string $column)

Create a new IP address column on the table.

macAddress(string $column)

Create a new MAC address 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.

rememberToken()

Adds the remember_token column to the table.

addColumn(string $type, string $name, array $parameters = array())

Add a new column to the blueprint.

$this
removeColumn(string $name)

Remove a column from the schema blueprint.

string
getTable()

Get the table the blueprint describes.

array
getColumns()

Get the columns on the blueprint.

array
getCommands()

Get the commands on the blueprint.

array
getAddedColumns()

Get the columns on the blueprint that should be added.

array
getChangedColumns()

Get the columns on the blueprint that should be changed.

Details

in Macroable at line line 24
static void macro(string $name, callable $macro)

Register a custom macro.

Parameters

string $name
callable $macro

Return Value

void

in Macroable at line line 35
static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line line 49
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line line 71
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line line 67
void __construct(string $table, Closure $callback = null)

Create a new schema blueprint.

Parameters

string $table
Closure $callback

Return Value

void

at line line 83
void build(Connection $connection, Grammar $grammar)

Execute the blueprint against the database.

Parameters

Connection $connection
Grammar $grammar

Return Value

void

at line line 97
array toSql(Connection $connection, Grammar $grammar)

Get the raw SQL statements for the blueprint.

Parameters

Connection $connection
Grammar $grammar

Return Value

array

at line line 184
Fluent create()

Indicate that the table needs to be created.

Return Value

Fluent

at line line 194
void temporary()

Indicate that the table needs to be temporary.

Return Value

void

at line line 204
Fluent drop()

Indicate that the table should be dropped.

Return Value

Fluent

at line line 214
Fluent dropIfExists()

Indicate that the table should be dropped if it exists.

Return Value

Fluent

at line line 225
Fluent dropColumn(array|mixed $columns)

Indicate that the given columns should be dropped.

Parameters

array|mixed $columns

Return Value

Fluent

at line line 239
Fluent renameColumn(string $from, string $to)

Indicate that the given columns should be renamed.

Parameters

string $from
string $to

Return Value

Fluent

at line line 250
Fluent dropPrimary(string|array $index = null)

Indicate that the given primary key should be dropped.

Parameters

string|array $index

Return Value

Fluent

at line line 261
Fluent dropUnique(string|array $index)

Indicate that the given unique key should be dropped.

Parameters

string|array $index

Return Value

Fluent

at line line 272
Fluent dropIndex(string|array $index)

Indicate that the given index should be dropped.

Parameters

string|array $index

Return Value

Fluent

at line line 283
Fluent dropForeign(string|array $index)

Indicate that the given foreign key should be dropped.

Parameters

string|array $index

Return Value

Fluent

at line line 293
void dropTimestamps()

Indicate that the timestamp columns should be dropped.

Return Value

void

at line line 303
void dropTimestampsTz()

Indicate that the timestamp columns should be dropped.

Return Value

void

at line line 313
void dropSoftDeletes()

Indicate that the soft delete column should be dropped.

Return Value

void

at line line 323
void dropSoftDeletesTz()

Indicate that the soft delete column should be dropped.

Return Value

void

at line line 333
void dropRememberToken()

Indicate that the remember token column should be dropped.

Return Value

void

at line line 344
Fluent rename(string $to)

Rename the table to a given name.

Parameters

string $to

Return Value

Fluent

at line line 357
Fluent primary(string|array $columns, string $name = null, string|null $algorithm = null)

Specify the primary key(s) for the table.

Parameters

string|array $columns
string $name
string|null $algorithm

Return Value

Fluent

at line line 370
Fluent unique(string|array $columns, string $name = null, string|null $algorithm = null)

Specify a unique index for the table.

Parameters

string|array $columns
string $name
string|null $algorithm

Return Value

Fluent

at line line 383
Fluent index(string|array $columns, string $name = null, string|null $algorithm = null)

Specify an index for the table.

Parameters

string|array $columns
string $name
string|null $algorithm

Return Value

Fluent

at line line 395
Fluent foreign(string|array $columns, string $name = null)

Specify a foreign key for the table.

Parameters

string|array $columns
string $name

Return Value

Fluent

at line line 406
Fluent increments(string $column)

Create a new auto-incrementing integer (4-byte) column on the table.

Parameters

string $column

Return Value

Fluent

at line line 417
Fluent tinyIncrements(string $column)

Create a new auto-incrementing tiny integer (1-byte) column on the table.

Parameters

string $column

Return Value

Fluent

at line line 428
Fluent smallIncrements(string $column)

Create a new auto-incrementing small integer (2-byte) column on the table.

Parameters

string $column

Return Value

Fluent

at line line 439
Fluent mediumIncrements(string $column)

Create a new auto-incrementing medium integer (3-byte) column on the table.

Parameters

string $column

Return Value

Fluent

at line line 450
Fluent bigIncrements(string $column)

Create a new auto-incrementing big integer (8-byte) column on the table.

Parameters

string $column

Return Value

Fluent

at line line 462
Fluent char(string $column, int $length = null)

Create a new char column on the table.

Parameters

string $column
int $length

Return Value

Fluent

at line line 476
Fluent string(string $column, int $length = null)

Create a new string column on the table.

Parameters

string $column
int $length

Return Value

Fluent

at line line 489
Fluent text(string $column)

Create a new text column on the table.

Parameters

string $column

Return Value

Fluent

at line line 500
Fluent mediumText(string $column)

Create a new medium text column on the table.

Parameters

string $column

Return Value

Fluent

at line line 511
Fluent longText(string $column)

Create a new long text column on the table.

Parameters

string $column

Return Value

Fluent

at line line 524
Fluent integer(string $column, bool $autoIncrement = false, bool $unsigned = false)

Create a new integer (4-byte) column on the table.

Parameters

string $column
bool $autoIncrement
bool $unsigned

Return Value

Fluent

at line line 537
Fluent tinyInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)

Create a new tiny integer (1-byte) column on the table.

Parameters

string $column
bool $autoIncrement
bool $unsigned

Return Value

Fluent

at line line 550
Fluent smallInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)

Create a new small integer (2-byte) column on the table.

Parameters

string $column
bool $autoIncrement
bool $unsigned

Return Value

Fluent

at line line 563
Fluent mediumInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)

Create a new medium integer (3-byte) column on the table.

Parameters

string $column
bool $autoIncrement
bool $unsigned

Return Value

Fluent

at line line 576
Fluent bigInteger(string $column, bool $autoIncrement = false, bool $unsigned = false)

Create a new big integer (8-byte) column on the table.

Parameters

string $column
bool $autoIncrement
bool $unsigned

Return Value

Fluent

at line line 588
Fluent unsignedInteger(string $column, bool $autoIncrement = false)

Create a new unsigned integer (4-byte) column on the table.

Parameters

string $column
bool $autoIncrement

Return Value

Fluent

at line line 600
Fluent unsignedTinyInteger(string $column, bool $autoIncrement = false)

Create a new unsigned tiny integer (1-byte) column on the table.

Parameters

string $column
bool $autoIncrement

Return Value

Fluent

at line line 612
Fluent unsignedSmallInteger(string $column, bool $autoIncrement = false)

Create a new unsigned small integer (2-byte) column on the table.

Parameters

string $column
bool $autoIncrement

Return Value

Fluent

at line line 624
Fluent unsignedMediumInteger(string $column, bool $autoIncrement = false)

Create a new unsigned medium integer (3-byte) column on the table.

Parameters

string $column
bool $autoIncrement

Return Value

Fluent

at line line 636
Fluent unsignedBigInteger(string $column, bool $autoIncrement = false)

Create a new unsigned big integer (8-byte) column on the table.

Parameters

string $column
bool $autoIncrement

Return Value

Fluent

at line line 649
Fluent float(string $column, int $total = 8, int $places = 2)

Create a new float column on the table.

Parameters

string $column
int $total
int $places

Return Value

Fluent

at line line 662
Fluent double(string $column, int|null $total = null, int|null $places = null)

Create a new double column on the table.

Parameters

string $column
int|null $total
int|null $places

Return Value

Fluent

at line line 675
Fluent decimal(string $column, int $total = 8, int $places = 2)

Create a new decimal column on the table.

Parameters

string $column
int $total
int $places

Return Value

Fluent

at line line 686
Fluent boolean(string $column)

Create a new boolean column on the table.

Parameters

string $column

Return Value

Fluent

at line line 698
Fluent enum(string $column, array $allowed)

Create a new enum column on the table.

Parameters

string $column
array $allowed

Return Value

Fluent

at line line 709
Fluent json(string $column)

Create a new json column on the table.

Parameters

string $column

Return Value

Fluent

at line line 720
Fluent jsonb(string $column)

Create a new jsonb column on the table.

Parameters

string $column

Return Value

Fluent

at line line 731
Fluent date(string $column)

Create a new date column on the table.

Parameters

string $column

Return Value

Fluent

at line line 742
Fluent dateTime(string $column)

Create a new date-time column on the table.

Parameters

string $column

Return Value

Fluent

at line line 753
Fluent dateTimeTz(string $column)

Create a new date-time column (with time zone) on the table.

Parameters

string $column

Return Value

Fluent

at line line 764
Fluent time(string $column)

Create a new time column on the table.

Parameters

string $column

Return Value

Fluent

at line line 775
Fluent timeTz(string $column)

Create a new time column (with time zone) on the table.

Parameters

string $column

Return Value

Fluent

at line line 786
Fluent timestamp(string $column)

Create a new timestamp column on the table.

Parameters

string $column

Return Value

Fluent

at line line 797
Fluent timestampTz(string $column)

Create a new timestamp (with time zone) column on the table.

Parameters

string $column

Return Value

Fluent

at line line 807
void timestamps()

Add nullable creation and update timestamps to the table.

Return Value

void

at line line 821
void nullableTimestamps()

Add nullable creation and update timestamps to the table.

Alias for self::timestamps().

Return Value

void

at line line 831
void timestampsTz()

Add creation and update timestampTz columns to the table.

Return Value

void

at line line 844
Fluent softDeletes(string $column = 'deleted_at')

Add a "deleted at" timestamp for the table.

Parameters

string $column

Return Value

Fluent

at line line 854
Fluent softDeletesTz()

Add a "deleted at" timestampTz for the table.

Return Value

Fluent

at line line 865
Fluent binary(string $column)

Create a new binary column on the table.

Parameters

string $column

Return Value

Fluent

at line line 876
Fluent uuid(string $column)

Create a new uuid column on the table.

Parameters

string $column

Return Value

Fluent

at line line 887
Fluent ipAddress(string $column)

Create a new IP address column on the table.

Parameters

string $column

Return Value

Fluent

at line line 898
Fluent macAddress(string $column)

Create a new MAC address column on the table.

Parameters

string $column

Return Value

Fluent

at line line 910
void morphs(string $name, string|null $indexName = null)

Add the proper columns for a polymorphic table.

Parameters

string $name
string|null $indexName

Return Value

void

at line line 926
void nullableMorphs(string $name, string|null $indexName = null)

Add nullable columns for a polymorphic table.

Parameters

string $name
string|null $indexName

Return Value

void

at line line 940
Fluent rememberToken()

Adds the remember_token column to the table.

Return Value

Fluent

at line line 1012
Fluent addColumn(string $type, string $name, array $parameters = array())

Add a new column to the blueprint.

Parameters

string $type
string $name
array $parameters

Return Value

Fluent

at line line 1027
$this removeColumn(string $name)

Remove a column from the schema blueprint.

Parameters

string $name

Return Value

$this

at line line 1067
string getTable()

Get the table the blueprint describes.

Return Value

string

at line line 1077
array getColumns()

Get the columns on the blueprint.

Return Value

array

at line line 1087
array getCommands()

Get the commands on the blueprint.

Return Value

array

at line line 1097
array getAddedColumns()

Get the columns on the blueprint that should be added.

Return Value

array

at line line 1109
array getChangedColumns()

Get the columns on the blueprint that should be changed.

Return Value

array