 
  Schema Builder
Laravel 提供 Schema 類別來維護資料表。通常會寫在 migration 檔,使用程式碼來快速建立資料表。操作資料表的常用方法
建立資料表
Schema::create('posts', function($table){
    $table->increments('id');
    $table->string('title');
    $table->string('content');
    $table->timestamps();
});
CREATE TABLE `posts` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `title` varchar(255) NOT NULL DEFAULT '',
    `content` varchar(255)  NOT NULL DEFAULT '',
    `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
    `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
    PRIMARY KEY (`id`)
)
資料表更名
Schema::rename($from, $to);
刪除資料表
Schema::drop('posts');
Schema::dropIfExists('posts');
新增欄位
Schema::table('posts', function($table)
{
    $table->string('tag');
});
刪除欄位
Schema::table('posts', function($table)
{
    $table->dropColumn('tag');
});
欄位更名
Schema::table('posts', function($table)
{
    $table->renameColumn('from', 'to');
});
      本文網址:http://blog.tonycube.com/2015/01/laravel-17-schema-builder.html
由 Tony Blog 撰寫,請勿全文複製,轉載時請註明出處及連結,謝謝 😀
由 Tony Blog 撰寫,請勿全文複製,轉載時請註明出處及連結,謝謝 😀
 
 
我要留言
留言小提醒:
1.回覆時間通常在晚上,如果太忙可能要等幾天。
2.請先瀏覽一下其他人的留言,也許有人問過同樣的問題。
3.程式碼請先將它編碼後再貼上。(線上編碼:http://bit.ly/1DL6yog)
4.文字請加上標點符號及斷行,難以閱讀者恕難回覆。
5.感謝您的留言,您的問題也可能幫助到其他有相同問題的人。