【发布时间】:2013-12-02 15:51:03
【问题描述】:
如何在两列上设置唯一约束?
class MyModel extends Migration {
public function up()
{
Schema::create('storage_trackers', function(Blueprint $table) {
$table->increments('id');
$table->string('mytext');
$table->unsignedInteger('user_id');
$table->engine = 'InnoDB';
$table->unique('mytext', 'user_id');
});
}
}
MyMode::create(array('mytext' => 'test', 'user_id' => 1);
// this fails??
MyMode::create(array('mytext' => 'test', 'user_id' => 2);
【问题讨论】:
-
遗憾的是,Laravel docs 中缺少此级别的详细信息。顺便提一下很容易。像这样的细节和 - 例如 - 框架似乎总是假设每个表都会自动递增
id,这给框架带来了边缘的业余感觉。我在吐槽吗? :-(