---
description: >-
  https://www.itsolutionstuff.com/post/laravel-migration-add-enum-column-exampleexample.html
---

# Laravel Migration Add Enum Column Example, products (ok)

C:\xampp\htdocs\reset\database\migrations\2022\_05\_20\_184747\_create\_products\_table.php

```
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductsTable extends Migration {
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up() {
    Schema::create('products', function (Blueprint $table) {
      $table->id();
      $table->string('name');
      $table->enum('status', ['Pending', 'Wait', 'Active'])->default('Pending');
      $table->timestamps();
    });
  }
  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down() {
    Schema::dropIfExists('products');
  }
}
```

C:\xampp\htdocs\reset\database\migrations\2022\_05\_20\_190100\_update\_status\_column.php

```
<?php
use Illuminate\Database\Migrations\Migration;
class UpdateStatusColumn extends Migration {
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up() {
    DB::statement("ALTER TABLE `products` CHANGE `status` `status` ENUM('Pending','Wait','Active', 'Completed') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Pending';");
  }
  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down() {
    //
  }
}
```

![](https://1592565776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LVfVRgKBlsVnWvhnDaa%2Fuploads%2FsLCn29LeFRlNoV6AMFXW%2FScreenshot_7.png?alt=media\&token=2bac51d1-7f3c-4d9b-a8ed-d552890de762)

![](https://1592565776-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LVfVRgKBlsVnWvhnDaa%2Fuploads%2FgA2UWZPPgrdW8e5ZdL6q%2FScreenshot_8.png?alt=media\&token=b3acbb1d-274b-4e77-984e-0820e0fc9c04)

## Laravel Migration Add Enum Column Example

By Hardik Savani April 27, 2021 Category : Laravel![](https://a.vdo.ai/core/assets/img/cross.svg)PlayUnmuteLoaded: 1.20%Fullscreen[![VDO.AI](https://a.vdo.ai/core/assets/img/logo.svg)](https://vdo.ai/?utm_medium=video\&utm_term=itsolutionstuff.com\&utm_source=vdoai_logo)Here, i will show you laravel migration add enum column. let’s discuss about laravel migration enum column. let’s discuss about laravel migration add enum value. this example will help you how to add enum column in laravel migration.

Sometime we take column like status and you have specified values for it like pending, active, completed etc. at that time you can choose enum data type in mysql. but if you want to add enum data type in laravel migration then how you can add enum data type column in laravel.

However, i will show you examples of how to add enum column in laravel migration, how to set default value of enum column using laravel migration and how to update value on enum column in laravel migration. you can also use it in laravel 6, laravel 7, laravel 8 and laravel 9 version.

let's see bellow examples:

**Add Enum Data Type Column:**

```
<?php  use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\Schema;  class CreateProductsTable extends Migration{    /**     * Run the migrations.     *     * @return void     */    public function up()    {        Schema::create('products', function (Blueprint $table) {            $table->id();            $table->string('name');            $table->enum('status', ['Pending', 'Wait', 'Active']);            $table->timestamps();        });    }      /**     * Reverse the migrations.     *     * @return void     */    public function down()    {        Schema::dropIfExists('products');    }}
```

**Add Enum Column with Default Value:**

```
<?php  use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\Schema;  class CreateProductsTable extends Migration{    /**     * Run the migrations.     *     * @return void     */    public function up()    {        Schema::create('products', function (Blueprint $table) {            $table->id();            $table->string('name');            $table->enum('status', ['Pending', 'Wait', 'Active'])->default('Pending');            $table->timestamps();        });    }      /**     * Reverse the migrations.     *     * @return void     */    public function down()    {        Schema::dropIfExists('products');    }}
```

**Update Enum Column Values:**

we will add new option call "Completed", you can see how i added.

Read Also: [How to Rollback Migration in Laravel?](https://www.itsolutionstuff.com/post/how-to-rollback-migration-in-laravelexample.html)

```
<?php  use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\Schema;  class UpdateStatusColumn extends Migration{    /**     * Run the migrations.     *     * @return void     */    public function up()    {        \DB::statement("ALTER TABLE `products` CHANGE `status` `status` ENUM('Pending','Wait','Active', 'Completed') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Pending';");    }    /**     * Reverse the migrations.     *     * @return void     */    public function down()    {              }}
```

you can see bellow screen shot:

![](https://www.itsolutionstuff.com/upload/laravel-migration-enum.png)

i hope it can help you....
