times(10) ->make() ->each(function ($user, $index) use ($faker, $avatars) { // 从头像数组中随机取出一个并赋值 $user->avatar = $faker->randomElement($avatars); }); // 让隐藏字段可见,并将数据集合转换为数组 $user_array = $users->makeVisible(['password', 'remember_token'])->toArray(); // 插入到数据库中 \App\Models\User::insert($user_array); // 单独处理第一个用户的数据 $user = \App\Models\User::find(1); $user->name = 'fthvgb1'; $user->email = 'fthvgb1@163.com'; $user->avatar = ''; $user->save(); } }