Support the ongoing development of Laravel.io →
posted 8 years ago
Architecture
Last updated 2 years ago.
0

how deep is the route going to be?, that is the question.

since the routes matches only the given pattern you need to have a depth limit. This should work until 4 levels.

Route::get('/{slug1}/{slug2?}/{slug3?}/{slug4?}', ['uses'=>'CategoryController@categoryByCategoryslugView']);

You can however dynamically create the string you're passing in to the ::get method. To do that get the current url, remove the app url, explode with '/', format each element with curly brackets, numbers and the question mark, then implode with '/'. Back in the controller calling func_get_args should return you all the slugs as an array.

0

Hi @astroanu,

Thanks, your first suggestion don't work for me, as i said: "Yes, i know i can pass multiple variables to the function in the controller, but theres a certain reason why i want to pass the whole slug to the function."

I'm searching for a way to get the whole slug in once, including the slashes, is that possible in any way? if not, i have to add 20 times {slug?}, but would be better to send it in once...

Bart

0

The best solution I've come up with is:

Route::any('{all}', 'RouteController@handle')->where('all', '.*');
0

@elite123 yeah, i found that one in multiple way's on the web, but the .* don't seem to work for slashes in the url? as you can see in the opening post, it's allready in there, but doesn't work ;)

0

take a look at my last suggestion on dynamically creating the pattern. that's the easier way to implement this, otherwise you will have to change some of laravel's inner workings such as the kernel, and the controller dispatcher.

Last updated 8 years ago.
0

yeah, okey, but than its more clear to use just 20 slugs with? and just look how much of them has a value. i've made it that way now, and it works, but is would simply be better if there's a way to say to the router, just get everything after the parent routes and pass it to my function. just wondering what the where('all', '.*') part would normally do, and if it has to work with slashes and there's something wrong in my code, or that it's just something not possible in the router...

astroanu said:

take a look at my last suggestion on dynamically creating the pattern. that's the easier way to implement this, otherwise you will have to change some of laravel's inner workings such as the kernel, and the controller dispatcher.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

BartHuis barthuis Joined 19 May 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.