create(); $cateIds = SystemMediaCategory::pluck('id')->toArray(); if (!empty($cateIds)) { $faker = app(Faker\Generator::class); $media->each(function (SystemMedia $i) use ($cateIds, $faker) { $i->update(['category_id' => $faker->randomElement($cateIds)]); }); } } }