마이그레이션을 만들자(테이블만들기)
1 | php artisan make:migration create_board_names_table --create=board_names | cs |
마이그레이션 하기
1 | php artisan migrate | cs |
컨트롤러와 모델을 만들자
1 | php artisan make:controller Board_namesController -r -m Board_name | cs |
시더파일을 만들자
1 | php artisan make:seeder Board_namesTableSeeder | cs |
database/seeds/BoardNamesTableSeeder.php
1 2 3 4 | public function run() { factory(App\Board_name::class, 50)->create(); } | cs |
database/factories/BoardName.php 를 만들자.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <?php use App\Board_name; use Illuminate\Support\Str; use Faker\Generator as Faker; /* |-------------------------------------------------------------------------- | Model Factories |-------------------------------------------------------------------------- | | This directory should contain each of the model factory definitions for | your application. Factories provide a convenient way to generate new | model instances for testing / seeding your application's database. | */ $factory->define(Board_name::class, function (Faker $faker) { return [ 'board_name' => str_random(6), 'top_num' => rand(10,99), 'bot_num' => rand(10,99), 'unit' => str_random(10), 'note' => $faker->sentence(), ]; }); |
시더를 실행하자
1 | php artisan db:seed --class Board_namesTableSeeder | cs |
랜덤한 가짜 데이터가 입력되었다.