本文整理匯總了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);
}