## Schema
~~~php
// 創建指定數據表
Schema::create('table', function($table)
{
$table->increments('id');
});
// 指定一個連接
Schema::connection('foo')->create('table', function($table){});
// 通過給定的名稱來重命名數據表
Schema::rename($from, $to);
// 移除指定數據表
Schema::drop('table');
// 當數據表存在時, 將指定數據表移除
Schema::dropIfExists('table');
// 判斷數據表是否存在
Schema::hasTable('table');
// 判斷數據表是否有該列
Schema::hasColumn('table', 'column');
// 更新一個已存在的數據表
Schema::table('table', function($table){});
// 重命名數據表的列
$table->renameColumn('from', 'to');
// 移除指定的數據表列
$table->dropColumn(string|array);
// 指定數據表使用的存儲引擎
$table->engine = 'InnoDB';
// 字段順序,只能在 MySQL 中才能用
$table->string('name')->after('email');
~~~
### 索引
~~~php
$table->string('column')->unique();
$table->primary('column');
// 創建一個雙主鍵
$table->primary(array('first', 'last'));
$table->unique('column');
$table->unique('column', 'key_name');
// 創建一個雙唯一性索引
$table->unique(array('first', 'last'));
$table->unique(array('first', 'last'), 'key_name');
$table->index('column');
$table->index('column', 'key_name');
// 創建一個雙索引
$table->index(array('first', 'last'));
$table->index(array('first', 'last'), 'key_name');
$table->dropPrimary(array('column'));
$table->dropPrimary('table_column_primary');
$table->dropUnique(array('column'));
$table->dropUnique('table_column_unique');
$table->dropIndex(array('column'));
$table->dropIndex('table_column_index');
~~~
### 外鍵
~~~php
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'|'restrict'|'set null'|'no action');
$table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade'|'restrict'|'set null'|'no action');
$table->dropForeign(array('user_id'));
$table->dropForeign('posts_user_id_foreign');
~~~
### 字段類型
~~~php
// 自增
$table->increments('id');
$table->bigIncrements('id');
// 數字
$table->integer('votes');
$table->tinyInteger('votes');
$table->smallInteger('votes');
$table->mediumInteger('votes');
$table->bigInteger('votes');
$table->float('amount');
$table->double('column', 15, 8);
$table->decimal('amount', 5, 2);
// 字符串和文本
$table->char('name', 4);
$table->string('email');
$table->string('name', 100);
$table->text('description');
$table->mediumText('description');
$table->longText('description');
// 日期和時間
$table->date('created_at');
$table->dateTime('created_at');
$table->time('sunrise');
$table->timestamp('added_on');
// Adds created_at and updated_at columns
// 添加 created_at 和 updated_at 行
$table->timestamps();
$table->nullableTimestamps();
// 其它類型
$table->binary('data');
$table->boolean('confirmed');
// 為軟刪除添加 deleted_at 字段
$table->softDeletes();
$table->enum('choices', array('foo', 'bar'));
// 添加 remember_token 為 VARCHAR(100) NULL
$table->rememberToken();
// 添加整型的 parent_id 和字符串類型的 parent_type
$table->morphs('parent');
->nullable()
->default($value)
->unsigned()
->comment()
~~~
- 參考知識--非必學僅供必要時候查詢
- 知識清單
- Composer 安裝等
- artisan--創建模型-控制器-各種模塊
- Route--路由
- Paginate--分頁
- File--文件
- View--視圖
- template--模版
- Model--模型
- Schema--數據表索引-外鍵-字段類型
- DB-基本使用-查詢語句-joins-聚合--原生sql-增刪改查等
- message--消息
- Validation--驗證規則
- Auth-用戶認證-用戶權限
- Helper-數組對象-路徑-字符串-urls-links等
- Session會話
- Response--回應
- Request--請求
- Redirect--重定向
- Environment--環境
- Log--日志
- URL--地址
- Event--事件
- Input--輸入
- Security安全--哈希-加密解密
- Queue--監聽
- Container--容器
- Config--參數設置
- Cache--緩存
- Cookie--設置-獲取--刪除等
- Mail--郵件
- String--字符串
- Collection--集合
- Storage--存儲
- Lang--語言
- 單元測試
- 文件夾結構簡介
- 第一章 laravel8運行環境的搭建(已經有了運行環境的直接跳過)