Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created February 22, 2015 20:20
Show Gist options
  • Save james2doyle/a8dfeab09c9746271256 to your computer and use it in GitHub Desktop.
Save james2doyle/a8dfeab09c9746271256 to your computer and use it in GitHub Desktop.
Laravel common Route patterns. From http://laravel-tricks.com/tricks/routing-patterns
// Common Route Patterns http://laravel-tricks.com/tricks/routing-patterns
// Patterns
Route::pattern('id', '\d+');
Route::pattern('hash', '[a-z0-9]+');
Route::pattern('hex', '[a-f0-9]+');
Route::pattern('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}');
Route::pattern('base', '[a-zA-Z0-9]+');
Route::pattern('slug', '[a-z0-9-]+');
Route::pattern('username', '[a-z0-9_-]{3,16}');
// Usage
Route::get('users/{id}', 'UserController@getProfile');
Route::get('products/{id}', 'ProductController@getProfile');
Route::get('articles/{slug}', 'ArticleController@getFull');
Route::get('faq/{slug}', 'FaqController@getQuestion');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment