# How to Remove Column from Table in Laravel Migration? (ok)

C:\xampp\htdocs\reset\database\migrations\2022\_05\_20\_180539\_create\_posts\_table.php

```
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePostsTable extends Migration {
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up() {
    Schema::create('posts', function (Blueprint $table) {
      $table->id();
      $table->string('title');
      $table->text('body');
      $table->boolean('is_publish')->default(0);
      $table->timestamps();
    });
  }
  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down() {
    Schema::dropIfExists('posts');
  }
}
```

C:\xampp\htdocs\reset\database\migrations\2022\_05\_20\_180718\_change\_posts\_table\_column.php

```
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class ChangePostsTableColumn extends Migration {
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up() {
    // Schema::table('posts', function (Blueprint $table) {
    //   $table->dropColumn('body'); // Remove Column using Migration
    // });
    // Schema::table('posts', function (Blueprint $table) {
    //   $table->dropColumn(['body', 'title']); // Remove Multiple Column using Migration
    // });
    // if (Schema::hasColumn('posts', 'body')) {
    //   Schema::table('posts', function (Blueprint $table) {
    //     $table->dropColumn('body'); // Remove Column If Exists using Migration
    //   });
    // }
  }
  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down() {
    //
  }
}
```

Tương ứng 3 trường hợp là 3 bức ảnh&#x20;

![](/files/avwRYQRGni6BqbzDmbJA) ![](/files/NEbl1cFpW9qZIeKDjb6l) ![](/files/J4tXLuz60DA91AIX6FEm)

## How to Remove Column from Table in Laravel Migration?

By Hardik Savani April 1, 2020 Category : Laravel![](https://a.vdo.ai/core/assets/img/cross.svg)PlayUnmuteLoaded: 1.17%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)

Hi Artisan,

In this quick example, let's see laravel migration remove column. This post will give you simple example of how to drop column in laravel migration. i would like to show you remove column laravel migration. We will use drop field laravel migration.

you can easily drop column from database table in laravel 6, laravel 7, laravel 8 and laravel 9.

I will give you some example that way you can easily remove column using migration. let's see bellow example that will help you.

1\) Remove Column using Migration

2\) Remove Multiple Column using Migration

3\) Remove Column If Exists using Migration

**1) Remove Column using Migration**

```
<?php  use Illuminate\Support\Facades\Schema;use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;  class ChangePostsTableColumn extends Migration{    /**     * Run the migrations.     *     * @return void     */    public function up()    {        Schema::table('posts', function (Blueprint $table) {            $table->dropColumn('body');        });    }      /**     * Reverse the migrations.     *     * @return void     */    public function down()    {              }}
```

**2) Remove Multiple Column using Migration**

```
<?php  use Illuminate\Support\Facades\Schema;use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;  class ChangePostsTableColumn extends Migration{    /**     * Run the migrations.     *     * @return void     */    public function up()    {        Schema::table('posts', function (Blueprint $table) {            $table->dropColumn(['body', 'title']);        });    }      /**     * Reverse the migrations.     *     * @return void     */    public function down()    {              }}
```

**3) Remove Column If Exists using Migration**

Read Also: [How to Change Column Name and Data Type in Laravel Migration?](https://www.itsolutionstuff.com/post/how-to-change-column-name-and-data-type-in-laravel-migrationexample.html)

```
<?php  use Illuminate\Support\Facades\Schema;use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;  class ChangePostsTableColumn extends Migration{    /**     * Run the migrations.     *     * @return void     */    public function up()    {        if (Schema::hasColumn('posts', 'body')){              Schema::table('posts', function (Blueprint $table) {                $table->dropColumn('body');            });        }    }      /**     * Reverse the migrations.     *     * @return void     */    public function down()    {              }}
```

I hope it can help you...


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnphp.gitbook.io/learnphp/laravel-advanced/how-to-remove-column-from-table-in-laravel-migration-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
