Laravel Migration : Tipe Data



bigIncrements()

The bigIncrements method creates an auto-incrementing UNSIGNED BIGINT (primary key) equivalent column:

$table->bigIncrements('id');

bigInteger()

The bigInteger method creates a BIGINT equivalent column:

$table->bigInteger('votes');

binary()

The binary method creates a BLOB equivalent column:

$table->binary('photo');

When utilizing MySQL, MariaDB, or SQL Server, you may pass length and fixed arguments to create VARBINARY or BINARY equivalent column:

$table->binary('data', length: 16); // VARBINARY(16)

$table->binary('data', length: 16, fixed: true); // BINARY(16)

boolean()

The boolean method creates a BOOLEAN equivalent column:

$table->boolean('confirmed');

char()

The char method creates a CHAR equivalent column with of a given length:

$table->char('name', length: 100);

dateTimeTz()

The dateTimeTz method creates a DATETIME (with timezone) equivalent column with an optional fractional seconds precision:

$table->dateTimeTz('created_at', precision: 0);

dateTime()

The dateTime method creates a DATETIME equivalent column with an optional fractional seconds precision:

$table->dateTime('created_at', precision: 0);

date()

The date method creates a DATE equivalent column:

$table->date('created_at');

decimal()

The decimal method creates a DECIMAL equivalent column with the given precision (total digits) and scale (decimal digits):

$table->decimal('amount', total: 8, places: 2);

double()

The double method creates a DOUBLE equivalent column:

$table->double('amount');

enum()

The enum method creates a ENUM equivalent column with the given valid values:

$table->enum('difficulty', ['easy', 'hard']);

float()

The float method creates a FLOAT equivalent column with the given precision:

$table->float('amount', precision: 53);

foreignId()

The foreignId method creates an UNSIGNED BIGINT equivalent column:

$table->foreignId('user_id');

foreignIdFor()

The foreignIdFor method adds a {column}_id equivalent column for a given model class. The column type will be UNSIGNED BIGINT, CHAR(36), or CHAR(26) depending on the model key type:

$table->foreignIdFor(User::class);

foreignUlid()

The foreignUlid method creates a ULID equivalent column:

$table->foreignUlid('user_id');

foreignUuid()

The foreignUuid method creates a UUID equivalent column:

$table->foreignUuid('user_id');

geography()

The geography method creates a GEOGRAPHY equivalent column with the given spatial type and SRID (Spatial Reference System Identifier):

$table->geography('coordinates', subtype: 'point', srid: 4326);

Support for spatial types depends on your database driver. Please refer to your database's documentation. If your application is utilizing a PostgreSQL database, you must install the PostGIS extension before the geography method may be used.

geometry()

The geometry method creates a GEOMETRY equivalent column with the given spatial type and SRID (Spatial Reference System Identifier):

$table->geometry('positions', subtype: 'point', srid: 0);

Support for spatial types depends on your database driver. Please refer to your database's documentation. If your application is utilizing a PostgreSQL database, you must install the PostGIS extension before the geometry method may be used.

id()

The id method is an alias of the bigIncrements method. By default, the method will create an id column; however, you may pass a column name if you would like to assign a different name to the column:

$table->id();

increments()

The increments method creates an auto-incrementing UNSIGNED INTEGER equivalent column as a primary key:

$table->increments('id');

integer()

The integer method creates an INTEGER equivalent column:

$table->integer('votes');

ipAddress()

The ipAddress method creates a VARCHAR equivalent column:

$table->ipAddress('visitor');

When using PostgreSQL, an INET column will be created.

json()

The json method creates a JSON equivalent column:

$table->json('options');

jsonb()

The jsonb method creates a JSONB equivalent column:

$table->jsonb('options');

longText()

The longText method creates a LONGTEXT equivalent column:

$table->longText('description');

When utilizing MySQL or MariaDB, you may apply a binary character set to the column in order to create a LONGBLOB equivalent column:

$table->longText('data')->charset('binary'); // LONGBLOB

macAddress()

The macAddress method creates a column that is intended to hold a MAC address. Some database systems, such as PostgreSQL, have a dedicated column type for this type of data. Other database systems will use a string equivalent column:

$table->macAddress('device');

mediumIncrements()

The mediumIncrements method creates an auto-incrementing UNSIGNED MEDIUMINT equivalent column as a primary key:

$table->mediumIncrements('id');

mediumInteger()

The mediumInteger method creates a MEDIUMINT equivalent column:

$table->mediumInteger('votes');

mediumText()

The mediumText method creates a MEDIUMTEXT equivalent column:

$table->mediumText('description');

When utilizing MySQL or MariaDB, you may apply a binary character set to the column in order to create a MEDIUMBLOB equivalent column:

$table->mediumText('data')->charset('binary'); // MEDIUMBLOB

morphs()

The morphs method is a convenience method that adds a {column}_id equivalent column and a {column}_type VARCHAR equivalent column. The column type for the {column}_id will be UNSIGNED BIGINT, CHAR(36), or CHAR(26) depending on the model key type.

This method is intended to be used when defining the columns necessary for a polymorphic Eloquent relationship. In the following example, taggable_id and taggable_type columns would be created:

$table->morphs('taggable');

nullableTimestamps()

The nullableTimestamps method is an alias of the timestamps method:

$table->nullableTimestamps(precision: 0);

nullableMorphs()

The method is similar to the morphs method; however, the columns that are created will be "nullable":

$table->nullableMorphs('taggable');

nullableUlidMorphs()

The method is similar to the ulidMorphs method; however, the columns that are created will be "nullable":

$table->nullableUlidMorphs('taggable');

nullableUuidMorphs()

The method is similar to the uuidMorphs method; however, the columns that are created will be "nullable":

$table->nullableUuidMorphs('taggable');

rememberToken()

The rememberToken method creates a nullable, VARCHAR(100) equivalent column that is intended to store the current "remember me" authentication token:

$table->rememberToken();

set()

The set method creates a SET equivalent column with the given list of valid values:

$table->set('flavors', ['strawberry', 'vanilla']);

smallIncrements()

The smallIncrements method creates an auto-incrementing UNSIGNED SMALLINT equivalent column as a primary key:

$table->smallIncrements('id');

smallInteger()

The smallInteger method creates a SMALLINT equivalent column:

$table->smallInteger('votes');

softDeletesTz()

The softDeletesTz method adds a nullable deleted_at TIMESTAMP (with timezone) equivalent column with an optional fractional seconds precision. This column is intended to store the deleted_at timestamp needed for Eloquent's "soft delete" functionality:

$table->softDeletesTz('deleted_at', precision: 0);

softDeletes()

The softDeletes method adds a nullable deleted_at TIMESTAMP equivalent column with an optional fractional seconds precision. This column is intended to store the deleted_at timestamp needed for Eloquent's "soft delete" functionality:

$table->softDeletes('deleted_at', precision: 0);

string()

The string method creates a VARCHAR equivalent column of the given length:

$table->string('name', length: 100);

text()

The text method creates a TEXT equivalent column:

$table->text('description');

When utilizing MySQL or MariaDB, you may apply a binary character set to the column in order to create a BLOB equivalent column:

$table->text('data')->charset('binary'); // BLOB

timeTz()

The timeTz method creates a TIME (with timezone) equivalent column with an optional fractional seconds precision:

$table->timeTz('sunrise', precision: 0);

time()

The time method creates a TIME equivalent column with an optional fractional seconds precision:

$table->time('sunrise', precision: 0);

timestampTz()

The timestampTz method creates a TIMESTAMP (with timezone) equivalent column with an optional fractional seconds precision:

$table->timestampTz('added_at', precision: 0);

timestamp()

The timestamp method creates a TIMESTAMP equivalent column with an optional fractional seconds precision:

$table->timestamp('added_at', precision: 0);

timestampsTz()

The timestampsTz method creates created_at and updated_at TIMESTAMP (with timezone) equivalent columns with an optional fractional seconds precision:

$table->timestampsTz(precision: 0);

timestamps()

The timestamps method creates created_at and updated_at TIMESTAMP equivalent columns with an optional fractional seconds precision:

$table->timestamps(precision: 0);

tinyIncrements()

The tinyIncrements method creates an auto-incrementing UNSIGNED TINYINT equivalent column as a primary key:

$table->tinyIncrements('id');

tinyInteger()

The tinyInteger method creates a TINYINT equivalent column:

$table->tinyInteger('votes');

tinyText()

The tinyText method creates a TINYTEXT equivalent column:

$table->tinyText('notes');

When utilizing MySQL or MariaDB, you may apply a binary character set to the column in order to create a TINYBLOB equivalent column:

$table->tinyText('data')->charset('binary'); // TINYBLOB

unsignedBigInteger()

The unsignedBigInteger method creates an UNSIGNED BIGINT equivalent column:

$table->unsignedBigInteger('votes');

unsignedInteger()

The unsignedInteger method creates an UNSIGNED INTEGER equivalent column:

$table->unsignedInteger('votes');

unsignedMediumInteger()

The unsignedMediumInteger method creates an UNSIGNED MEDIUMINT equivalent column:

$table->unsignedMediumInteger('votes');

unsignedSmallInteger()

The unsignedSmallInteger method creates an UNSIGNED SMALLINT equivalent column:

$table->unsignedSmallInteger('votes');

unsignedTinyInteger()

The unsignedTinyInteger method creates an UNSIGNED TINYINT equivalent column:

$table->unsignedTinyInteger('votes');

ulidMorphs()

The ulidMorphs method is a convenience method that adds a {column}_id CHAR(26) equivalent column and a {column}_type VARCHAR equivalent column.

This method is intended to be used when defining the columns necessary for a polymorphic Eloquent relationship that use ULID identifiers. In the following example, taggable_id and taggable_type columns would be created:

$table->ulidMorphs('taggable');

uuidMorphs()

The uuidMorphs method is a convenience method that adds a {column}_id CHAR(36) equivalent column and a {column}_type VARCHAR equivalent column.

This method is intended to be used when defining the columns necessary for a polymorphic Eloquent relationship that use UUID identifiers. In the following example, taggable_id and taggable_type columns would be created:

$table->uuidMorphs('taggable');

ulid()

The ulid method creates a ULID equivalent column:

$table->ulid('id');

uuid()

The uuid method creates a UUID equivalent column:

$table->uuid('id');

year()

The year method creates a YEAR equivalent column:

$table->year('birth_year');


Modifier

ModifierDescription
->after('column')Place the column "after" another column (MySQL).
->autoIncrement()Set INTEGER columns as auto-incrementing (primary key).
->charset('utf8mb4')Specify a character set for the column (MySQL).
->collation('utf8mb4_unicode_ci')Specify a collation for the column.
->comment('my comment')Add a comment to a column (MySQL / PostgreSQL).
->default($value)Specify a "default" value for the column.
->first()Place the column "first" in the table (MySQL).
->from($integer)Set the starting value of an auto-incrementing field (MySQL / PostgreSQL).
->invisible()Make the column "invisible" to SELECT * queries (MySQL).
->nullable($value = true)Allow NULL values to be inserted into the column.
->storedAs($expression)Create a stored generated column (MySQL / PostgreSQL / SQLite).
->unsigned()Set INTEGER columns as UNSIGNED (MySQL).
->useCurrent()Set TIMESTAMP columns to use CURRENT_TIMESTAMP as default value.
->useCurrentOnUpdate()Set TIMESTAMP columns to use CURRENT_TIMESTAMP when a record is updated (MySQL).
->virtualAs($expression)Create a virtual generated column (MySQL / SQLite).
->generatedAs($expression)Create an identity column with specified sequence options (PostgreSQL).
->always()Defines the precedence of sequence values over input for an identity column (PostgreSQL).


Posting Komentar

Lebih baru Lebih lama