laravel/laravel — pull request #315 by ccschmitz (2012-02-07 04:16:54+00:00)
Title: Added a method to turn URI into associative array

Returns the URI as an associative array. For example:

example.com/category/12/inventory/in-stock/sort-by/price/

`to_assoc()` would return:

array(
'category' => 12,
'inventory' => 'in-stock',
'sort-by' => 'price'
);

This example illustrates how we are currently using this method, to filter/sort products.

You can use `$offset` to start parsing the URI at the specified segment, and if there is an odd number of segments, the last key will be set to null.

example.com/category/toys/inventory/in-stock/sort

Since there are 5 URI segments, `to_assoc()` would return:

array(
'category' => 'toys',
'inventory' => 'in-stock',
'sort' => null
);

If you had a URI of `/store/brand/nike/category/shoes` and set an offset of 1 you would get could bypass the `store` segment and get only the part of the URI you need. In this case, `to_assoc(1)` would return:

array(
'brand' => 'nike',
'category' => 'shoes',
);