建立與刪除數(shù)據(jù)表

2018-02-24 15:53 更新

要建立一個(gè)新的數(shù)據(jù)表,可使用 Schema::create 方法:

Schema::create('users', function($table)
{
    $table->increments('id');
});

傳入 create 方法的第一個(gè)參數(shù)是數(shù)據(jù)表名稱,第二個(gè)參數(shù)是 Closure 并接收 Blueprint 對(duì)象被用來定義新的數(shù)據(jù)表。

要修改數(shù)據(jù)表名稱,可使用 rename 方法:

Schema::rename($from, $to);

要指定特定連接來操作,可使用 Schema::connection 方法:

Schema::connection('foo')->create('users', function($table)
{
    $table->increments('id');
});

要移除數(shù)據(jù)表,可使用 Schema::drop 方法:

Schema::drop('users');
Schema::dropIfExists('users');
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)