Sometimes we want to parse the URL variables of a given route, ie getting the word user from /api/users/{user}. If we have: We get the following, which is not what we want unfortunately: Let’s take a look at how Lavavel router does this behind the scene.
In /src/illuminate/routing/route the toSymfonyRoute() function, we see: That looks very scary, but for typically use cases, we can simplify it to: The $route variable is an instance of SymfonyRoute . Once we got that, we can run the compile method, ie $route->compile() to get a compileRoute instance where we can get all the URL variables as an array. This is how the compiledRoute instance looks like: We can call the getVariables() method to get all the URL parameters / variables as an array.