Posted inTechnology / Laravel / Mysql / Programming

Laravel Drop hascolumn if exists in Migration

Today, We want to share with you Laravel Drop hascolumn if exists in Migration.In this post we will show you laravel eloquent check if record exists, hear for laravel check if model has column we will give you demo and example for implement.In this post, we will learn about how to create table through migration in laravel with an example.

Laravel Drop hascolumn if exists in Migration

There are the Following The simple About Laravel Drop hascolumn if exists in Migration Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel Migrations – Dropping columns, so the laravel check if column exists for this example is following below.

Laravel drop column using migration.

And then here We are going to explain how to drop column step by step.

We can display we can use simple hasColumn(), as We can display below:

Schema::hasColumn(my_db_table_name, my_column_name);

And then We can display below full Laravel migration source code with example:

increments('id');
            $table->string('product_name');
            $table->string('p_code')->unique();
            $table->string('p_rate');
            $table->rememberToken();
            $table->timestamps();
			
        });
    }
    public function down()
    {
        if (Schema::hasColumn('products', 'product_name'))
        {
            Schema::table('products', function (Blueprint $table)
            {
                $table->dropColumn('product_name');
            });
        }
    }
}

Last step To run the Database migration using command prompt.

php artisan migrate:rollback

Example 2: Laravel – Drop column if exists using migration

How to check column exists or not in table Laravel 5.7

if (Schema::hasColumn('subscriptions', 'stripe_id')) {
    Schema::table('subscriptions', function ($table) {
        $table->dropColumn('stripe_id');
    });
}
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

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

I hope you get an idea about Laravel Drop hascolumn if exists in Migration.
I would like to have feedback on my Pakainfo.com 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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype