In this reaction, potassium phthalimide gives phthalimide anion which acts as nucleophile and attacks electrophilic carbon of alkyl halide.
But due to much less reactivity of aryl halide (nucleophilic substitution reaction), 1° aromatic amines can’t be prepared.