Cmd/Ctrl + K

Schema

Use the schema builder to create and change tables.

Create tables

Define new tables with the schema builder inside a migration.

Schema changes normally belong in migrations.

Column types

Choose column methods according to the data each field must store.

MethodPurpose
id(name = 'id')Auto-incrementing id column and primary key.
string(name, length = 255)Variable-length string.
char(name, length = 255)Fixed-length string.
text(name)Text column.
mediumText(name)Medium text column.
longText(name)Long text column.
integer(name)Integer column.
bigInteger(name)Big integer column.
mediumInteger(name)Medium integer column.
smallInteger(name)Small integer column.
tinyInteger(name)Tiny integer column.
boolean(name)Boolean column.
decimal(name, precision = 8, scale = 2)Decimal column.
double(name, precision = 8, scale = 2)Double column.
float(name, precision = 8, scale = 2)Float column.
json(name)JSON column.
date(name)Date column.
datetime(name)Datetime column.
timestamp(name)Timestamp column.
time(name)Time column.
year(name)Year column.
uuid(name)UUID column.
timestamps()Nullable created_at and updated_at timestamps.

Column modifiers

Chain modifiers after a column definition to add constraints or metadata.

Available modifiers:

  • nullable(bool $value = true)
  • default(mixed $value)
  • unique()
  • primary()
  • autoIncrement()
  • unsigned(bool $value = true)
  • comment(string $comment)
  • change()

Indexes

Add indexes for uniqueness, primary keys, or frequently queried columns.

Foreign keys

Define foreign keys to enforce relationships between tables at the database level.

Foreign key helpers include onDelete(), onUpdate(), cascadeOnDelete(), restrictOnDelete(), nullOnDelete(), cascadeOnUpdate(), restrictOnUpdate(), and nullOnUpdate().

Alter tables

Use table() to add, rename, change, or remove columns on an existing table.

Table helpers include create(), table(), drop(), and dropIfExists().