Laravel – How to check column exists or not in table?
In this post we will give you information about Laravel – How to check column exists or not in table?. Hear we will give you detail about Laravel – How to check column exists or not in table?And how to use it also give you demo for it if it is necessary.
When i was working my laravel application at that time i need to remove column from database. But i am not sure that column is exists or not in tables. So i was thinking, but i found solution from Laravel Database Migration Schema. we can check column is exists or not in tabales using hasColumn. If you also need to remove if column is exists then you can use bellow example.
Example:
if (Schema::hasColumn('subscriptions', 'stripe_id')) {
Schema::table('subscriptions', function ($table) {
$table->dropColumn('stripe_id');
});
}
Hope this code and post will helped you for implement Laravel – How to check column exists or not in table?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs