Laravel 6 drop column if exists MySQL using Migration

Today, We want to share with you Laravel 6 drop column if exists MySQL using Migration.In this post we will show you Create a column if it does not exist in laravel 6, hear for laravel migration drop table if exists we will give you demo and example for implement.In this post, we will learn about Laravel drop column if exists Using Migration with an example.

Laravel 6 drop column if exists MySQL using Migration

There are the Following The simple About Check If a Column Exists in Laravel Migration File Full Information With Example and source code.

Read Also:  Laravel 6 schema Timestamps Example

As I will cover this Post with live Working example to develop laravel 6 migration drop table if exists, so the laravel 6 migration change column type is used for this example is following below.

Full example of drop column using migration


Schema::hasColumn(your_table_name, yout_table_column_name);

Step 1: Check If a Column Exists in Laravel Migration File


use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsTable extends Migration
    public function up()
        Schema::table('products', function (Blueprint $table) {
     public function down()
        if (Schema::hasColumn('products', 'slug'))
            Schema::table('products', function (Blueprint $table)

Step 2: run the migration using Terminal

php artisan migrate:rollback

Web Programming Tutorials Example with Demo

Read :

Read Also:  Clear Cache Programmatically in Laravel - Example


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel 6 remove table column if exists in database.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel Combine two DB query results Example
  2. Read Also:  Check if row exists using Laravel
  3. Read Also:  Simple PHP Rating System with database using JavaScript
  4. Read Also:  How to Print Arrays in PHP?
  5. Read Also:  Laravel MySQL Advanced Query Techniques with Example
  6. Read Also:  laravel get all table names
  7. Read Also:  Laravel Drop hascolumn if exists in Migration
  8. Read Also:  Laravel whereRaw havingRaw and orderByRaw Example
  9. Read Also:  Get Unique Collection values(Remove Duplicates from Collection) using Laravel
  10. Read Also:  Laravel Handling findOrFail exceptions