Laravel 数据库:判断字段是否存在 0 个改进

Schema::table('users', function (Blueprint $table) {
    if ($table->hasColumn('email')) {
        // 用户表里存在 Email
    }
});

上面的代码等价于下面的:

if (Schema::hasColumn('users', 'email'))
{
    // 
}
本文为 Wiki 文章,邀您参与纠错、纰漏和优化
讨论数量: 2

报这个错 Method Illuminate\Database\Schema\Blueprint::hasColumn does not exist.

4年前 评论
MangoDa

如判断多个字段是否存在,可使用 hasColumns 第二个参数为数组

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!