라라벨/게시판만들기
게시판 만드는 순서
땀모
2019. 5. 31. 06:18
[1. 데이터편]
1.테이블 만들기 테이블명(복수) : boardnames
1 | php artisan make:migration create_boardnames_table --create=boardnames | cs |
2. 테이블 컬럼을 작성하고 마이그레이션 실행
1 | php artisan migrate | cs |
3. 시더 만들기(가짜데이터 삽입을 위해서)
1 | php artisan make:seeder BoardnamesTableSeeder | cs |
4. BoardnamesTableSeeder 작성하기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php use Illuminate\Database\Seeder; class BoardnamesTableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { factory(App\Boardname::class, 50)->create(); } } | cs |
5. factories 파일만들고(BoardnameFactory) 작성하기
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\Boardname; 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(Boardname::class, function (Faker $faker) { return [ 'boardname' => str_random(6), 'top_num' => rand(10,99), 'bot_num' => rand(10,99), 'method' => str_random(3), 'note' => str_random(10), ]; }); | cs |
6. 시더실행하기 : 데이터가 삽입이된다.
1 | php artisan db:seed --class BoardnamesTableSeeder | cs |
[2. MVC편]
1. 컨트롤러 모델만들기 -r(resources) -m(모델생성) Boardname:모델명
1 | php artisan make:controller BoardnamesController -r -m Boardname | cs |
2. 컨트롤러에서 index 메서드 만들기