1

I want to be able to respond to a route in Larvel 3 that contains an unknown number of segments N. e.g.

/segment_1/...segment_N-1/segment_N

The route should send the value of each segment to an anonymous function.

I have tried using:

Route::get('/(:any)/(:all?)', function($segments){
    //do something
});

This accepts all routes, but only sends the first segment to the function

Is there a simple way in Laravel to achieve what I need?

GWed
  • 15,167
  • 5
  • 62
  • 99
  • I think that you can find your answer here: https://stackoverflow.com/questions/13297278/laravel-using-any-wildcard-for-all-routes I won't copy others answers and paste theme here.. :) – Pascut Feb 10 '13 at 16:02
  • thanks - have just found that one myself :-) - trying it out now. – GWed Feb 10 '13 at 16:03
  • ok, hope you'll find a solution (you can post it here so others will know in the future) – Pascut Feb 10 '13 at 16:05

1 Answers1

2

Not sure if the best way to do this, but it works for me.

 Route::get('(:all)?', function() {
    $current = URI::current();
    $segments = explode ('/', $current);
    foreach ($segments as $key => $value) {
        echo "URI Segment[" . $key . "]" . $value . "<br>";
    }
 });
Rodrigo Gauzmanf
  • 2,517
  • 1
  • 23
  • 26