In order to obtain the Friedmann equations from the Lagrangian formalism, as far as I understand, one way is to minimally couple a scalar field $\phi(t)$ to the FLRW metric, i.e.
$S=\int d^4 x \sqrt{-g} \bigg(R - \frac{1}{2} g_{\alpha\beta} \partial^\alpha \phi \partial^\beta \phi - V(\phi) \bigg)$.
Then, one computes the energy-momentum tensor $T^{\mu\nu}$ of the scalar field and identifies the pressure and energy density in terms of $d\phi/dt$ and $V$, one finds that the equations of motion derived from the action above are the Friedmann equations.
My question is: can one write the coupling of FLRW gravity to a perfect fluid in the Lagrangian formalism without introducing a scalar field in this way, instead perhaps with a term like $g_{\mu\nu}T^{\mu\nu}$?
Any kind of feedback would be appreciated.