Brachistochrone problem
The time to travel from point $p_1$ to $p_2$ is given by this integral $$t_{12}=\int_{p_1}^{p_2}\frac{ds}{v}.$$ With $ds=\sqrt{dx^2+dy^2}=\sqrt{1+y'^2}\,dx$ and $v=\sqrt{2g\,y}$, we obtain $$t_{12}=\int_{p_1}^{p_2}\underbrace{\sqrt{\frac{1+y'^2}{2g\,y(x)}}}_{f(y,y')}\,dx,$$ and because the function $f$ is Independent of $x$, we can use the Beltrami identity $$f-y'\frac{\partial f}{\partial y'}=c\tag 1$$ to obtain the solution.
Instead, I want to use a different approach. Taking $ds=\sqrt{\dot x^2+\dot y^2}\,dt$ and $v=\sqrt{2g\,y}$ gives $$ t_{12}\mapsto\int_{p_1}^{p_2}\frac{\sqrt{\dot x^2+\dot y^2}\,dt}{\sqrt{2g\,y}},$$ which implies $$f(y,\dot{y},\dot{x})=\sqrt{\frac{\dot{x}^2+\dot{y}^2}{2g\,y}}\equiv\mathcal L(y,\dot{y},\dot{x}).$$ So the first integral is $$\left(\frac{\partial \mathcal L}{\partial{\dot{x}}}\right)^2=c.\tag 2$$ From equation (2), I obtain the equation $$\frac{\dot x^2}{(\dot x^2+\dot y^2)\,y(t)}=c,$$ to which the solution is $$x(t)=\frac{k^2}{2}[t-\sin(t)],\\y(t)=\frac{k^2}{2}[1-\cos(t)]\quad,\text{where}~c=\frac{1}{2\,g\,k^2},$$ which is indeed the solution of brachistochrone problem.
So what is wrong with this approach?