Formation of planets via pebble accretion