라라벨 artisan db:seed

Jmnote (토론 | 기여)님의 2016년 5월 16일 (월) 01:33 판 (→‎개요)

1 개요

라라벨 artisan db:seed
  • DB에 시드 레코드를 입력하는 artisan 명령어

2 예시

root@zetawiki:/var/www/laravel# cat database/seeds/UsersTableSeeder.php 
<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class UsersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('users')->insert([
            'name' => str_random(10),
            'email' => str_random(10).'@gmail.com',
            'password' => bcrypt('secret'),
        ]);
    }
}
mysql> select * from users;
Empty set (0.00 sec)
root@zetawiki:/var/www/laravel# php artisan db:seed --class=UsersTableSeeder
root@zetawiki:/var/www/laravel# php artisan db:seed --class=UsersTableSeeder
root@zetawiki:/var/www/laravel#
mysql> select * from users\G
*************************** 1. row ***************************
            id: 1
          name: FfhvCfKlPv
         email: OjD3aczJrL@gmail.com
      password: $2y$10$u74XzN94HtCEQP2tYkHa1uKqer7ZN3BE6YtVZUGimvj0pS1w310Iy
remember_token: NULL
    created_at: NULL
    updated_at: NULL
*************************** 2. row ***************************
            id: 2
          name: bbqDMriejp
         email: XTRWUN477x@gmail.com
      password: $2y$10$3/Cm/BiNVK44J69rNf7uo.FEiDf/NiE1v9FAIcaOsflQjqVxyKbTq
remember_token: NULL
    created_at: NULL
    updated_at: NULL
2 rows in set (0.00 sec)

3 같이 보기

4 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}