Skip to content

Instantly share code, notes, and snippets.

@rbrisita
Created January 22, 2015 23:47
Show Gist options
  • Save rbrisita/87bb5c24edbca659dcb5 to your computer and use it in GitHub Desktop.
Save rbrisita/87bb5c24edbca659dcb5 to your computer and use it in GitHub Desktop.
Laravel 3 Route Contraint / Parameter Validation with Regular Expressions
/**
*
* Below emulates Laravel 4 Regular Expression Route Constraints in Laravel 3.
*
**/
/**
* Application Route Validation Patterns
* Router::patterns['(:name)'] = '(regex pattern)';
*/
\Laravel\Routing\Router::$patterns['(:yyyy)'] = '([0-9]{4})';
\Laravel\Routing\Router::$patterns['(:mm-dd)'] = '([0-9]{2}-[0-9]{2})';
/**
* Application Routes
**/
Route::get('/', 'app@index');
Route::get('/(:yyyy)', 'app@year'); // YYYY
Route::get('/(:yyyy)/(:mm-dd)', 'app@date'); // YYYY/MM-DD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment