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

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

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.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →