# PHP語法 migration:app>provider ### Database、Migration 轉移表(Migration)有點像是資料庫(Datebase)的規格書(藍圖),可以用來定義資料庫有甚麼表單,欄位,格式,甚至表單之間的關聯性。而在laravel中,有提供Schema builder,這個套件會自動產生基本格式讓使用者建立表單更加方便。 那如何利用laravel建立有Schema builder的Migration呢? 1. 在終端機介面輸入指令, 在單純建立表單的狀態下只需要符合以下資訊 ```php= php artisan make:migration 表單名 ``` 2. 但為了建立表單時同時引用Schema builder就必須要這樣命名 (注意下方命名規則) ```php= php artisan make:migration create_表單名_table //表單名必須為s結尾(建議使用英文單字複數) //表單名如有多個單字需用底線分隔 ``` 使用指令建立完表單之後,可以在/database/migrations裡面找到剛建立了migration表單,接下來就可以用Migration來建立Datebase 3. 編輯migration ### php artisan migration add_title_to_table --create=products - 新建migration的同時,指定儲存表格為products - 同時新增一新Table、migration及model - 大駝峰 - migration會自動以 (表格名)TestPost 中的大寫字區分並加上複數,將model名稱建立為 test_posts ### 各式語法 `php artisan make:model TestPost -m `php artisan migrate:rollback` `php artisan create:migrate product` `php artisan migrate:rollback` 回復上一動 `php artisan migrate:refresh` `php artisan migrate` 將vscode中的表格資料更新至資料庫 `php artisan make:model Product` 名稱小駝峰+單數 `php artisan make:controller ProductController --resource` `php artisan make:controller ProductController -r` 名稱大駝峰+單數、建立附帶create、delete等function的Controller `php artisan migration add_title_to_table --table=products`新建migration的同時,指定儲存表格為products `php artisan migration add_title_to_table --create=products` - route - 路徑:routes - controller - 路徑:Http>Controllers - model - 路徑:App - template - 路徑:resources>views>layouts - admin - 路徑:resources>views>admin
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up