In earlier exercises, I have derived the formula of divergence in spherical coordinates as $$\textrm{div }\vec{v}= \frac{1}{r^2}\frac{\partial (r^2 v_r)}{\partial r}+\frac{1}{r \sin \vartheta}(\frac{\partial(v_{\vartheta}\sin \vartheta)}{\partial \vartheta}+\frac{\partial v_{\varphi}}{\partial \varphi})$$ with a vector field $\vec{v}(\vec{r})=v_rê_r+v_{\varphi}ê_{\varphi}+v_{\vartheta}ê_{\varphi}$ as well as the formula for the gradient as $$\nabla=\frac{\partial}{\partial r}ê_r+\frac{1}{r}\frac{\partial}{\partial \varphi}ê_{\varphi}+\frac{1}{r \sin{\varphi}}\frac{\partial}{\partial \vartheta}ê_{\vartheta}$$.
Now I am asked to concatenate the gradient with the divergence to arrive at the formula for the Laplacian of a scalar-field $f(r,\varphi,\vartheta)$, which is defined as the divergence of the gradient, but I am slightly confused. Looking at the solution, I get: $$\Delta = \frac{1}{r^2}\frac{\partial}{\partial r}(r^2 \frac{\partial f}{\partial r})+\frac{1}{r^2 \sin \vartheta}(\frac{\partial}{\partial \vartheta}(\sin \vartheta \frac{\partial f}{\partial \vartheta})+\frac{\partial^2 f}{\partial \varphi^2})$$. I can see that it follows the definition, somehow, but why do we put the factors from the gradient before the partial derivatives of the divergence and the partial derivatives from the gradient after the partial derivatives from the divergence?