Laravel组合三个或两个独特的值

时间:2014-11-23 09:51:44

标签: php laravel

我想输入其中customername,pan,mobile columns的组合必须唯一的行,所以我使用

$table->unique('customername', 'pan', 'mobile');

现在是否所有三个价值组合都是独一无二的,或者三个中的哪两个都是唯一的?

我想要的是三者的组合必须是独一无二的。

我在尝试上面时遇到了这个错误

"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'newCust' for key 'pan' (SQL: insert into `customers` (`customername`, `pan`, `customertype`, `email`, `mobile`, `offadd`, `now`, `referer_id`, `updated_at`, `created_at`) values (newCust, 1234, sasdfsdf, sdfsdf@sfdlfsdf.com, 4567, adsfasdf, sdfsdf, 2, 2014-11-23 09:47:43, 2014-11-23 09:47:43))"

完整架构

        $table->increments('id');
        $table->string('customername');
        $table->string('pan');
        $table->string('customertype');
        $table->string('email');
        $table->string('mobile');
        $table->unique('customername', 'pan', 'mobile');
        $table->text('offadd');
        $table->text('comadd');
        $table->string('website');
        $table->string('now');
        $table->string('companyname');
        $table->date('dob');
        $table->integer('referer_id');
        $table->string('status');
        $table->timestamps();

1 个答案:

答案 0 :(得分:2)

根据this answer,您可以尝试:

$table->unique(array('customername', 'pan', 'mobile'));
相关问题