Answers for "laravel migration check if column exists"

PHP
2

laravel drop column if exists

if (Schema::hasColumn('users', 'phone')) {
 	Schema::table('users', function (Blueprint $table){
       $table->dropColumn('phone');
    });
}
Posted by: Guest on November-13-2020
0

laravel migration check if table has column

// You may check for the existence of a table or column
// using the hasTable and hasColumn methods:

if (Schema::hasTable('users')) {
    // The "users" table exists...
}

if (Schema::hasColumn('users', 'email')) {
    // The "users" table exists and has an "email" column...
}
Posted by: Guest on January-14-2021

Code answers related to "laravel migration check if column exists"

Browse Popular Code Answers by Language