samedi 24 août 2019

Passing computed parameters to middleware

I would like to pass a computed value into my middleware through my web.php routes file. I have this model configuration:

Planet hasMany Countries

Country hasMany Cities

City hasMany Buildings

In all of my routes I need to build a menu that helps navigate between planets. So, no matter what I'm doing I need to be able to access the planet->id. Right now, in my middleware I have a long series of if/elseif checking to see which parameters exist in the URL:

if (isset($parameters['planet'])) $planetId = $parameters['planet']->id;
else if (isset($parameters['country'])) $planetId = $parameters['country']->planet->id;
else if (isset($parameters['building'])) $planetId = $parameters['building']->country->planet->id;

Obviously this gets very unwieldy very quickly and I feel like there should be a better way to pass the planetId into the middleware but I cannot find any way to gracefully do that...

Thank you very much for your help!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire