The Lagrangian is a simple statement of the energy of a system.
Have you heard of the relationship between energy and time?
Have you heard of the principle
of least time for photons?
Have you considered that a "photon" is not a wave or particle of energy before it is detected, but rather the probability that one will be detected?