Created
January 22, 2015 23:47
-
-
Save rbrisita/87bb5c24edbca659dcb5 to your computer and use it in GitHub Desktop.
Laravel 3 Route Contraint / Parameter Validation with Regular Expressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 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