mercredi 14 octobre 2015

Getting route path inside global middleware

I am trying to insert the path of the route inside of a meta tag so that I can use it to do some tracking using a 3rd partie's tracking script.

I would like to do this using a global middleware but have had no success.

I've tried setting up a view composer inside a global middleware and am using \Route::getCurrentRoute()->getPath() to grab the path of the route to be able to insert it inside of my view. It seems \Route::getCurrentRoute() always returns null at this point.

It works fine inside of a route middleware (probably because the route has already been constructed), but this would be a pain to place on every single route.

Just for clarification, by route path, I mean if you have a route setup like {year}/{make}/{model} and you go to the page 2015/jeep/wrangler, the route path would still be {year}/{make}/{model} and that would be placed inside of the meta tag.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire