Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nilo's avatar
Level 4

Manually Run Route Parameter Binding?

Is there a way to manually run a string through Laravel's route parameter binding? Basically I need to create routes dynamically.

For example - give the route:

Route::get('/posts/{slug}', 'SomeController@show');

I'd like to take it one step further and parse the slug as it may contain additional parameters.

// User visits
// example.com/posts/foobar-something-bizbaz

// Our dynamic slug looks like this 
$slug = "foobar-{word}-bizbaz";

// In this case the value of word is
$word = "something";

// Another post could have a different slug
// example.com/posts/{another_word}-yada-yada

In the controller or middleware, I'd like to run the slug through whatever Laravel parses routes with to extract the value of {word} and make a query using that value. I could probably cobble together a regex, but Laravel already does exactly what I need.

Any suggestions?

0 likes
2 replies
Nilo's avatar
Level 4

Thanks for the reply. I don’t think that’s quite it. I’m sure I’ve explained it poorly.

To put it another way, I need to get the route parameters from a dynamically generated route segment.

The slug parameter contains another parameter that I need the value of. But the value of slug is dynamic and can’t be hard coded in the routes.

Please or to participate in this conversation.