I am creating a directory that lists professionals with SEO friendly URLs. An example would look something like this:
/professionals/state-name-slug/city-name-slug/professional-name-slug/professional-id
So far nothing unusual. Currently in my routing I pass each url subdirectory after /professionals as a dynamic parameter, so you could imagine that my route looks like this:
Route::get('/professionals/{stateSlug}/{citySlug}/{nameSlug}/{professional}')->name('show-professional')
I'm realizing that this is problematic. Because I want to show my urls with the state name instead of the abbreviation, and the very large database I'm using stores the abbreviation with the professional. Because of this, I am doing a look up each time from my states table to get that state name slug, which seems unnecessary and wasteful.
What I would like to do is store the professional's "full slug" with his/her record, so the slug stored on the professional would look like
$professional->slug == '/state-name-slug/city-name-slug/professional-name-slug/'
Then I would simply look them up by the ID at the end of the full url:
/{fullSlug}/{professional}
After I make this switch, I realized that Laravel expects either more or less variables to be passed to the route. Since {fullSlug} is actually multiple sub directories, I get errors. What I am trying to figure out is can I let Laravel know that all of the sub directories before the id are just vanity / dynamic?