# laravel seed 使用紀錄 * ==Backend\Lai\group_web\database\seeds\DatabaseSeeder.php== - 會在資料庫增加下列InfoTypeTableSeeder裡面的資料,可換其他Seeder。 - 寫在run裡面的會在php artisan db:seed時執行 ```php= public function run() { $this->call(InfoTypeTableSeeder::class); } ``` - 在CMD下指令php artisan make:seeder Names(Table)Seeder - 會在\database\seeds\下增加該名Seeder - 在新增的Seeder==InfoTypeTableSeeder==內填入要增加的資料 ```php= public function run() { InfoTypes::insert([ [ 'name' => '123', 'created_at' => now()->toDateString(), 'updated_at' => now()->toDateString(), ], [ 'name' => '456', 'created_at' => now()->toDateString(), 'updated_at' => now()->toDateString(), ], [ 'name' => '789', 'created_at' => now()->toDateString(), 'updated_at' => now()->toDateString(), ], ]); } ``` # 指令整理 - 新增Seeder的資料 php artisan db:seed - (好像是)重新migrate後填入seed設定好的資料 php artisan migrate:refresh --seed - 建立Seeder php artisan make:seeder Names(Table)Seeder - 有問題的時候照順序下這2個指令 1. composer dump-autoload 2. php artisan db:seed
×
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