-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: any and all routes #39
Comments
Firstly, a 404 in L4 is handled by catching a How you do the same in L4 is by appending <?php
// GET /foo/123/some/other/value/here
// GET /foo/a123/sdf will not work as "a123" is not numeric.
Route::get('foo/{bar}/{baz}', function($bar, $baz)
{
// $bar == 123
// $baz == 'some/other/value/here'
})->where('bar', '\d+') // Digits
->where('baz', '.*'); // Anything
// You can modify your REGEX to suit:
// GET /foo/a123/asdf
// GET /foo/z123/asdf
// GEt /foo/df123/asdkfjsd
Route::get('foo/{bar}/{baz}', function($bar, $baz)
{
})->where('bar', '[a-z]{1,2}\d+') // 1-2 Letters + Digits
->where('baz', '.*'); // Anything Have a look at http://symfony.com/doc/2.0/components/routing/introduction.html for more as L4 uses the Symfony routing as it's backbone. Also, check out http://gskinner.com/RegExr/ for a really intuitive way to build up regular expressions :) |
That's it, ty very much. +1 Route::any('{all}', function(){
return 'It Works';
})->where('all', '.*'); |
No problem, glad I could help. I was a bit disappointed to see (:all) go at first until I saw the potential of this solution! I'd recommend closing the issue now :) |
This is covered in the Laravel docs at four.laravel.com is it not? Also, @jasonlewis has a great blog post on this issue. |
None of the above works in Laravel 4.0. Here is the solution: Route::any('{firstPart}/{rest}', function($firstPart, $rest){
return Response::make($firstPart . ", " . $rest);
})->where('firstPart', '[^/]*')->where('rest', '.*'); |
Well in L3 we could redirect any user request to a custom controller using Route::any('(:any), (:any)/(:all)', 'mycontroller@index');
With the changes in L4 i kinda see this idea lost, so please (re)implement the feature in L4.
I don't know a beautiful alternative to that problem in L4, i guess i could listen for 404 pages, get the values of the URL myself and start over there, but that's an ugly solution, if anyone knows any better ways, please tell me.
The text was updated successfully, but these errors were encountered: