Shouldn't your url http://www.site.com/cat1/abcdefghijklmnopqr
actually be http://www.site.com/test/cat1/abcdefghijklmnopqr
mcraz, you are correct. The URL's I typed were to illustrate my intended effect, I should have been a bit more cohesive with my example. I have corrected the URL's in my original post to reflect my example route. Thanks!
Any ideas?
Regex101.com suggests that your regex is incorrect. http://regex101.com/
Did you mean to escape the last /
before the question mark?
meigwilym, good catch. Interesting though, because it works (with the exception of the 18th character). With the regex updated to: ([-a-zA-Z0-9]+/?)* which now passes regex101, it still has the same 18th character issue....
I appreciate the help! Any other ideas?
Hi.
I test your problem and i see error
Try this code
Route::pattern('cat', '[A-Za-z0-9+_-]+');
Route::get('test/{cat}/{slug}', function($cat, $slug) {
return "cat: " . $cat . " slug: " . $slug;
});
or
Route::any('test/{cat}/{slug}', function($cat,$slug){
echo $cat;
echo $slug;
})->where('cat','[A-Za-z0-9+_-]+');
I think problem at
([-a-zA-Z0-9]+\/?)*
Have fun
tuyenlaptrinh, thank you. However, that doesn't address multiple categories. The regex is working. I can pull the categories and slug. The problem is that the slug is limited in length and I can't figure out why. I am not sure this is related to the regex as the problem happens on the {slug}/$slug parameter where no pattern is applied. I believe this because I can return the $cat and $slug and see the expected results for category and slug, until the slug exceeds 17 characters. Or, am I thinking of this totally wrong?
My skype vietcms.vn
Can i support for you via skype.
I really don't know your problem.
Sorry, this problem has remained unsolved and was on the back burner until now. I updated the original post to include a test site to illustrate my problem:
You can test this at www.trashaccount.com/test/cat/slug (www.trashaccount.com/test/{category1}/{category2}/.../{slug}
www.trashaccount.com/test/one/two/three/four/five/six/seven/eight -- this works www.trashaccount.com/test/one/two/abcdefghijklmnopqrstuvwxyz/three/four/five -- this works
It is the last slug that can't be longer than 17 characters, so this: www.trashaccount.com/test/one/two/three/abcdefghijklmnopqrs -- doesn't work.
To clarify the issue another time: This pattern allows me to have unlimited categories, the categories can be of any length, it is the final element, the slug, that can't be longer than 17 characters which is very limiting. I can't figure out why that is the only element being limited. Please help :)
I beat my head against the wall for a few more hours and started playing with the regex pattern. I couldn't get the idea out of my head that I was matching the final forwardslash of the categories, but also defining that forwardslash as the separator between {cat} and {slug} in the Route. This suspicion directed me towards positive lookaheads to remove the final forwardslash and slug from the result.
To be completely honest, I am not sure if this was the problem or not as I eventually resorted to easter egging regular expressions until I found something that works:
Route::pattern('cat2', '.+(?=\/.+)');
This pattern matches any character (.) one or more times (), followed by (?=) a forwardslash (/), any character (.) one or more times () without including it in the search (functionality of a positive lookahead ?=).
This can be verified at www.trashaccount.com/test2/cat1/cat2/veryverylongslugthatshouldbreak.
If anybody would like to correct me, or expand on this it would be greatly appreciated.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community