isEmpty()) { $this->call(AdminRolesTableSeeder::class); $roles = AdminRole::all(); } $perms = AdminPermission::pluck('id'); if ($perms->isEmpty()) { $this->call(AdminPermissionsTableSeeder::class); $perms = AdminPermission::pluck('id'); } $faker = app(Faker\Generator::class); $roles->each(function (AdminRole $role) use ($faker, $perms) { $role->permissions() ->attach($faker->randomElements($perms, $faker->numberBetween(0, 5))); }); } }