Home Laravel How to check column exists or not in table in Laravel?

How to check column exists or not in table in Laravel?

by Shahriar Sagor

Today now in this post i will show you How to check column exists or not in table in Laravel? When i was start to working my new laravel application at that time i was need to remove a column from the database. But i am not sure that the column is exists or not in my DB tables. So here i was thinking, but i was found a solution from Laravel Database Migration Schema. We can check the column is exists or not in tables by using hasColumn. If you also need to remove any one if column is not exists then you can use the bellow example.

Example:
if (Schema::hasColumn('subscriptions', 'stripe_id')) {
    Schema::table('subscriptions', function ($table) {
        $table->dropColumn('stripe_id');
    });
}

Read Also : How to convert Object into Array in PHP?

Thanks for read. I hope it help you. For more you can follow us on facebook.

close

You may also like