8. The function
$$
f(x)=\sqrt{3} \sin 2 x+2 \sin x+4 \sqrt{3} \cos x
$$

has a maximum value of . $\qquad$
8. $\frac{17}{2}$.

From the problem, we know
$$
\begin{array}{l}
f(x)=2 \sqrt{3} \sin x \cdot \cos x+2 \sqrt{3} \cos x+ \\
2 \sin x+2 \sqrt{3} \cos x \\
=2 \sqrt{3}(\cos x)(1+\sin x)+2(\sin x+\sqrt{3} \cos x) \\
\leqslant 2\left(\frac{\sqrt{3} \cos x+1+\sin x}{2}\right)^{2}+4 \sin \left(x+\frac{\pi}{3}\right) \\
\leqslant 2\left(\sin \left(x+\frac{\pi}{3}\right)+\frac{1}{2}\right)^{2}+4 \sin \left(x+\frac{\pi}{3}\right) \\
\leqslant 2\left(1+\frac{1}{2}\right)^{2}+4=\frac{17}{2} \text {, } \\
\text { when and only when }\left\{\begin{array}{l}
\sqrt{3} \cos x+1=\sin x+2, \\
\sin \left(x+\frac{\pi}{3}\right)=1,
\end{array}\right. \text { that is } \\
x=2 k \pi+\frac{\pi}{6}(k \in \mathbf{Z}) \\
\end{array}
$$

the equality holds.
Therefore, the maximum value of the function is $\frac{17}{2}$.