Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a bit complex approach. So you'll have to declare a new function in global.php:</p> <pre><code>function getFilters($filters) { $exploded = explode('|', $filters); foreach($exploded as $filter) { $filterClass = ucwords($filter).'Filter'; $return = with(new $filterClass)-&gt;filter(); if( $return === null ) return strtolower($filter); } return strtolower($filters); } </code></pre> <p>Now the next thing is to use "classes" for your filters. This is filters.php:</p> <pre><code>Route::filter('test', 'TestFilter'); Route::filter('test2', 'Test2Filter'); class TestFilter { public function filter() { if( 1 == 1 ) return Redirect::to('/'); } } class Test2Filter { public function filter() { if( 1 == 2 ) return Redirect::to('/'); } } </code></pre> <p>And finally, you'll have to call "getFilters()" on the route and pass to it the filters you want (instead of before=> 'test|test2'):</p> <pre><code>Route::get('test', array('before' =&gt; getFilters('test|test2'), function(){ dd('Hello'); })); </code></pre> <h3>Now the explanation:</h3> <p>The aim of the <code>getFilters()</code> function is to test filters before they get called on the route, if one of them doesn't return something this will make the function return just the filter who succeeded to before(). In the example above, test2 will fail, but test will succeed, so the function will just return test as a filter to the route. Now, if the 2 filters fail, the function will return the filters string so that Laravel will take care of the response.</p> <p><strong>Note:</strong> It's prefereable to pass CamelCaseLongName as filter string so that <code>getFilters()</code> calls the corresponding class correctly. The returned string to <code>before</code> will always be lowercase.</p> <p>You can then customize <code>getFilters()</code> so that it parses strings to get what's after the colons as parameters, just like you'd do it with normal filters (ex: test|test2:param1,param2')</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload