1.通过运行 Artisan 命令 make:seeder
来生成 Seeder。由框架生成的 seeders 都将被放置在 database/seeds
目录下:
php artisan make:seeder BankSeeder
2.一个 seeder 类只包含一个默认方法:run。这个方法会在 Artisan 命令 db:seed 被执行时调用。在 run 方法里你可以根据需要在数据库中插入数据。你也可以用 查询构造器 或 Eloquent 模型工厂 来手动插入数据。
<?php
use Illuminate\Database\Seeder;
use Carbon\Carbon;
class BankSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
$now = Carbon::now();
app('db')->table('bank')->insert([
[
'id' => '1',
'bank_name' => '中国工商银行',
'bank_image' => 'web_data/resource/images/bank/1.png',
'bank_code' => 'ICBC',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '2',
'bank_name' => '中国农业银行',
'bank_image' => 'web_data/resource/images/bank/2.png',
'bank_code' => 'ABC',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '3',
'bank_name' => '中国建设银行',
'bank_image' => 'web_data/resource/images/bank/3.png',
'bank_code' => 'CCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '4',
'bank_name' => '招商银行',
'bank_image' => 'web_data/resource/images/bank/4.png',
'bank_code' => 'CMB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '5',
'bank_name' => '中国光大银行',
'bank_image' => 'web_data/resource/images/bank/5.png',
'bank_code' => 'CEB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '6',
'bank_name' => '中国邮政储蓄银行',
'bank_image' => 'web_data/resource/images/bank/6.png',
'bank_code' => 'PSBC',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '7',
'bank_name' => '兴业银行',
'bank_image' => 'web_data/resource/images/bank/7.png',
'bank_code' => 'CIB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '8',
'bank_name' => '中国银行',
'bank_image' => 'web_data/resource/images/bank/8.png',
'bank_code' => 'BOC',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '9',
'bank_name' => '交通银行',
'bank_image' => 'web_data/resource/images/bank/9.png',
'bank_code' => 'COMM',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '10',
'bank_name' => '中信银行',
'bank_image' => 'web_data/resource/images/bank/10.png',
'bank_code' => 'CITIC',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '11',
'bank_name' => '华夏银行',
'bank_image' => 'web_data/resource/images/bank/11.png',
'bank_code' => 'HXBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '12',
'bank_name' => '广东发展银行',
'bank_image' => 'web_data/resource/images/bank/15.png',
'bank_code' => 'GDB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '13',
'bank_name' => '深圳发展银行',
'bank_image' => 'web_data/resource/images/bank/16.png',
'bank_code' => 'SDB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '14',
'bank_name' => '中国民生银行',
'bank_image' => 'web_data/resource/images/bank/17.png',
'bank_code' => 'CMBC',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '15',
'bank_name' => '浙商银行',
'bank_image' => 'web_data/resource/images/bank/23.png',
'bank_code' => 'CZBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '16',
'bank_name' => '上海农商银行',
'bank_image' => 'web_data/resource/images/bank/24.png',
'bank_code' => 'SHRCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '17',
'bank_name' => '渤海银行',
'bank_image' => 'web_data/resource/images/bank/26.png',
'bank_code' => 'BOHAIB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '18',
'bank_name' => '徽商银行',
'bank_image' => 'web_data/resource/images/bank/29.png',
'bank_code' => 'HSBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '19',
'bank_name' => '平安银行',
'bank_image' => 'web_data/resource/images/bank/30.png',
'bank_code' => 'SPABANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '20',
'bank_name' => '浦发银行',
'bank_image' => 'web_data/resource/images/bank/31.png',
'bank_code' => 'SPDB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '21',
'bank_name' => '甘肃省农村信用社联合社',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'GSRCU',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '22',
'bank_name' => '北京银行',
'bank_image' => 'web_data/resource/images/bank/5d3137dd5d31d.png',
'bank_code' => 'BJBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '23',
'bank_name' => '上海银行',
'bank_image' => 'web_data/resource/images/bank/5d3139184c364.png',
'bank_code' => 'SHBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '24',
'bank_name' => '吉林银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'JLBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '25',
'bank_name' => '南昌银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'NCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '26',
'bank_name' => '广州银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'GCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '27',
'bank_name' => '广州农村商业银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'GRCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '28',
'bank_name' => '珠海华润银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'RBOZ',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '29',
'bank_name' => '深圳农村商业银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'SRCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '30',
'bank_name' => '杭州银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'HZCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '31',
'bank_name' => '齐鲁银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'QLBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '32',
'bank_name' => '南京银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'NJCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '33',
'bank_name' => '晋商银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'JSB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '34',
'bank_name' => '兰州银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'LZYH',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '35',
'bank_name' => '宁夏银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'NXBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '36',
'bank_name' => '天津银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'TCCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '37',
'bank_name' => '河北银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'BHB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '38',
'bank_name' => '西安银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'XABANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '39',
'bank_name' => '大连银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'DLB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '40',
'bank_name' => '重庆农村商业银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'CRCBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '41',
'bank_name' => '重庆银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'CQBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '42',
'bank_name' => '郑州银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'ZZBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '43',
'bank_name' => '宁波银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'NBBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '44',
'bank_name' => '东莞农村商业银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'DRCBCL',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '45',
'bank_name' => '东莞银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'BOD',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '46',
'bank_name' => '广东南粤银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'NYBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '47',
'bank_name' => '苏州银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'BOSZ',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '48',
'bank_name' => '辽宁省农村信用社',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'LNRCC',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '49',
'bank_name' => '辽阳银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'LYCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '50',
'bank_name' => '福建省农村信用社联合社',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'FJNX',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '51',
'bank_name' => '泉州银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'BOQZ',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '52',
'bank_name' => '德州银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'DZBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '53',
'bank_name' => '东营银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'DYCCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '54',
'bank_name' => '莱商银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'LSBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '55',
'bank_name' => '临商银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'LSBC',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '56',
'bank_name' => '齐商银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'ZBCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '57',
'bank_name' => '日照银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'RZB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '58',
'bank_name' => '泰安银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'TACCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '59',
'bank_name' => '威海市商业银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'WHCCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '60',
'bank_name' => '潍坊银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'BANKWF',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '61',
'bank_name' => '青岛银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'QDCCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '62',
'bank_name' => '湖南省农村信用社联合社',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'HNRCC',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '63',
'bank_name' => '四川省农村信用社联合社',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'SCRCU',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '64',
'bank_name' => '贵阳银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'GYCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '65',
'bank_name' => '贵州省农村信用社联合社',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'GZRCU',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '66',
'bank_name' => '陕西省农村信用社联合社',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'SXRCCU',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '67',
'bank_name' => '长安银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'CABANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '68',
'bank_name' => '邯郸银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'HDBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '69',
'bank_name' => '张家口银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'ZJKCCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '70',
'bank_name' => '九江银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'JJBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '71',
'bank_name' => '上饶银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'SRBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '72',
'bank_name' => '柳州银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'LZCCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '73',
'bank_name' => '内蒙古银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'H3CB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '74',
'bank_name' => '甘肃银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'GSBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '75',
'bank_name' => '青海银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'BOQH',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '76',
'bank_name' => '乌鲁木齐银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'URMQCCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '77',
'bank_name' => '海口联合农村商业银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'UBCHN',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '78',
'bank_name' => '江南农村商业银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'CZRCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '79',
'bank_name' => '常熟农商银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'CSRCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '80',
'bank_name' => '包商银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'BSB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '81',
'bank_name' => '汉口银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'HKB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '82',
'bank_name' => '桂林银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'GLBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '83',
'bank_name' => '金华银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'JHBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '84',
'bank_name' => '沧州银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'BOCZ',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '85',
'bank_name' => '中原银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'ZYB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '86',
'bank_name' => '北京农商银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'BJRCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '87',
'bank_name' => '福建海峡银行',
'bank_image' => 'web_data/resource/images/bank/32.png',
'bank_code' => 'FJHXBC',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '88',
'bank_name' => '天津农商银行',
'bank_image' => 'web_data/resource/images/bank/5ecc7c232034b.png',
'bank_code' => 'TRCB',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '89',
'bank_name' => '江苏银行',
'bank_image' => 'web_data/resource/images/bank/5ece214f298a0.jpg',
'bank_code' => 'JSBANK',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '90',
'bank_name' => '东亚银行',
'bank_image' => 'web_data/resource/images/bank/5f1661d5012eb.jpg',
'bank_code' => 'HKBEA',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
[
'id' => '91',
'bank_name' => '哈尔滨银行',
'bank_image' => 'web_data/resource/images/bank/5f913b0fb535b.jpg',
'bank_code' => 'HARBIN',
'is_show' => 1,
'created_at' => $now,
'updated_at' => $now,
],
]);
}
}
3.运行 Seeders#
完成 seeder 类的编写之后,你可能需要使用 dump-autoload
命令重新生成 Composer 的自动加载器:
composer dump-autoload
接着就可以使用 Artisan 命令 db:seed 来填充数据库了。默认情况下,db:seed 命令将运行 DatabaseSeeder 类,这个类可以用来调用其它 Seed 类。不过,你也可以使用 --class 选项来指定一个特定的 seeder 类:
php artisan db:seed
php artisan db:seed --class=BankSeeder