Check If Database Table Has Column in Laravel

Laravel comes with a handy built-in hasColumn method which allows the developers to determine whether a a specific column exists in a particular table or not.

You can use hasColumn method as follows;

if(Schema::hasColumn('users', 'email'))
{
    //do something if email column exists inside users table
}

The above code will check if an email column exists inside the users table.

Quick Tip : How to Override Default Controller Namespace in Laravel

0 Comments

Leave a Comment.