Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Allow filter patterns to supply a name and callback as an easier alternative. #854

Merged
merged 2 commits into from about 2 years ago

3 participants

Jason Lewis Kirk Bushell Taylor Otwell
Jason Lewis

Currently you can only supply the name of a registered filter to filter patterns. This now allows you to supply a name and callback to the method to save on precious lines. ;)

Route::filter('pattern: admin/*', array('name' => 'admin.auth', function()
{
    // Do some nifty things in here.
}));

Can I get some +1's!?

Sent in regards to http://forums.laravel.com/viewtopic.php?pid=9966
Would like to know if people would find this useful. Cheers.

jasonlewis added some commits
Jason Lewis jasonlewis Allow filter patterns to supply a name and callback as an easier alte…
…rnative.

Signed-off-by: Jason Lewis <jason.lewis1991@gmail.com>
ac810f8
Jason Lewis jasonlewis Updated the documentation.
Signed-off-by: Jason Lewis <jason.lewis1991@gmail.com>
cea48d4
Kirk Bushell

+1 to this for sure, well done jason :)

Taylor Otwell
Owner

Cool idea. Would you mind making necessary updates to docs in this pull?

Jason Lewis

Its already been done mate! Check the diff. :)

Taylor Otwell taylorotwell merged commit 990f10f into from
Taylor Otwell
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Jun 24, 2012
Jason Lewis jasonlewis Allow filter patterns to supply a name and callback as an easier alte…
…rnative.

Signed-off-by: Jason Lewis <jason.lewis1991@gmail.com>
ac810f8
Jason Lewis jasonlewis Updated the documentation.
Signed-off-by: Jason Lewis <jason.lewis1991@gmail.com>
cea48d4
This page is out of date. Refresh to see the latest.
9 laravel/documentation/routing.md
Source Rendered
@@ -152,6 +152,15 @@ Sometimes you may want to attach a filter to all requests that begin with a give
152 152
153 153 Route::filter('pattern: admin/*', 'auth');
154 154
  155 +Optionally you can register filters directly when attaching filters to a given URI by supplying an array with the name of the filter and a callback.
  156 +
  157 +#### Defining a filter and URI pattern based filter in one:
  158 +
  159 + Route::filter('pattern: admin/*', array('name' => 'auth', function()
  160 + {
  161 + //
  162 + }));
  163 +
155 164 <a name="global-filters"></a>
156 165 ## Global Filters
157 166
9 laravel/routing/route.php
@@ -213,6 +213,15 @@ protected function patterns()
213 213 {
214 214 if (Str::is($pattern, $this->uri))
215 215 {
  216 + // If the filter provided is an array then we need to register
  217 + // the filter before we can assign it to the route.
  218 + if (is_array($filter))
  219 + {
  220 + list($filter, $callback) = array_values($filter);
  221 +
  222 + Filter::register($filter, $callback);
  223 + }
  224 +
216 225 $filters[] = $filter;
217 226 }
218 227 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.