Column Types and Modifiers


Numeric Types

Type

Description

tinyInteger

-128 to 127 or 0 to 255 (unsigned)

smallInteger

-32,768 to 32,767

integer

-2,147,483,648 to 2,147,483,647

bigInteger

Large range

decimal

Fixed point (e.g., money)

float

Floating point

double

More precision than float

unsigned()

Makes any integer positive-only


String & Text

Type

Description

string

VARCHAR (default length 255)

char

Fixed-length string

text

Long text

mediumText, longText

Even longer text


Date & Time

Type

Description

date

Date only

datetime

Date & time

timestamp

Date & time (auto-filled often)

timestamps

Adds created_at and updated_at

softDeletes

Adds deleted_at for soft delete


JSON & Others

Type

Description

json

Stores JSON

uuid

Universally unique ID

binary

Binary data

enum

$table->enum('level', ['basic', 'pro']);


Common Column Modifiers

Modifier

Description

Example

->nullable()

Allows column to store NULL

$table->string('name')->nullable();

->default(value)

Sets a default value

$table->boolean('active')->default(true);

->unique()

Adds a unique constraint

$table->string('email')->unique();

->index()

Adds a basic index

$table->string('slug')->index();

->primary()

Sets the column as primary key

$table->uuid('id')->primary();

->after('col')

Puts this column after another (MySQL only)

$table->string('token')->after('email');

->first()

Makes this the first column (MySQL only)

$table->string('first_name')->first();

->change()

Used when modifying an existing column

$table->string('title', 500)->nullable()->change();

->unsigned()

Makes an integer column unsigned (positive only)

$table->integer('votes')->unsigned();

->charset()

Overrides charset per column (rare)

$table->string('name')->charset('utf8mb4');

->collation()

Overrides collation

$table->string('name')->collation('utf8mb4_bin');

->autoIncrement()

Sets column to auto-increment

$table->integer('custom_id')->autoIncrement();


Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.