本文整理汇总了PHP中Illuminate\Database\Schema\Blueprint::foreign方法的典型用法代码示例。如果您正苦于以下问题:PHP Blueprint::foreign方法的具体用法?PHP Blueprint::foreign怎么用?PHP Blueprint::foreign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Schema\Blueprint
的用法示例。
在下文中一共展示了Blueprint::foreign方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildDynamicTable
protected function buildDynamicTable(Blueprint $table)
{
$block_index = 'FK_' . $this->getDynamicTableName() . '_block_id_blocks';
$page_index = 'FK_' . $this->getDynamicTableName() . '_page_id_pages';
$table->increments('id');
$table->integer('block_id')->unsigned()->nullable();
$table->integer('page_id')->unsigned()->nullable();
$table->integer('is_shared')->unsigned()->nullable();
$table->foreign('block_id', $block_index)->references('id')->on('blocks')->onUpdate('CASCADE')->onDelete('SET NULL');
$table->foreign('page_id', $page_index)->references('id')->on('pages')->onUpdate('CASCADE')->onDelete('SET NULL');
$table->timestamps();
}
示例2: buildDynamicTable
protected function buildDynamicTable(Blueprint $table)
{
$reference_column = $this->getDynamicType() . '_id';
$reference_table = $this->getDynamicType() . 's';
$reference_index = 'FK_' . $this->getDynamicTableName() . '_' . $reference_column . '_' . $reference_table;
$table->increments('id');
$table->integer($reference_column)->unsigned()->nullable();
$table->foreign($reference_column, $reference_index)->references('id')->on($reference_table)->onUpdate('CASCADE')->onDelete('SET NULL');
$table->timestamps();
}
示例3: testAddingForeignKey
public function testAddingForeignKey()
{
$blueprint = new Blueprint('users');
$blueprint->foreign('foo_id')->references('id')->on('orders');
$statements = $blueprint->toSql($this->getGrammar());
$this->assertEquals(1, count($statements));
$this->assertEquals('alter table `users` add constraint users_foo_id_foreign foreign key (`foo_id`) references `orders` (`id`)', $statements[0]);
}
示例4: testAddingForeignKeyWithCascadeDelete
public function testAddingForeignKeyWithCascadeDelete()
{
$blueprint = new Blueprint('users');
$blueprint->foreign('foo_id')->references('id')->on('orders')->onDelete('cascade');
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertEquals(1, count($statements));
$this->assertEquals('alter table users add constraint users_foo_id_foreign foreign key ( foo_id ) references orders ( id ) on delete cascade', $statements[0]);
}
示例5: testAddingForeignKey
public function testAddingForeignKey()
{
$blueprint = new Blueprint('users');
$blueprint->create();
$blueprint->string('foo')->primary();
$blueprint->string('order_id');
$blueprint->foreign('order_id')->references('id')->on('orders');
$statements = $blueprint->toSql($this->getGrammar());
$this->assertEquals(1, count($statements));
$this->assertEquals('create table "users" ("foo" varchar not null, "order_id" varchar not null, foreign key("order_id") references "orders"("id"), primary key ("foo"))', $statements[0]);
}
示例6: createKey
/**
* Create a foreign key on the given table.
*
* @param \Illuminate\Database\Schema\Blueprint $table
* @param \Stidges\LaravelFkMigration\ForeignKey $key
* @return void
*/
protected function createKey(Blueprint $table, ForeignKey $key)
{
$table->foreign($key->column)->references($key->references)->on($key->on)->onUpdate($key->onUpdate)->onDelete($key->onDelete);
}