Leptoquark models for the $B$-physics anomalies