table('employee'); $table->addColumn('initials', 'string', ['comment'=> '首字母', 'default'=> '']) ->update(); $where[] = ['name','<>','']; $where[] = ['name','not null','']; $arr = Employee::where($where)->column('id,name,initials'); foreach ($arr as $k => $v) { $initials = strtoupper(substr(hanzi2pinyin($v['name']),0,1)); Employee::where('id',$v['id'])->update(['initials'=>$initials]); } } }