Skip to content

Instantly share code, notes, and snippets.

@isurum
Last active June 16, 2017 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isurum/736baf5fde1c8c3cc339058f9bdefa4b to your computer and use it in GitHub Desktop.
Save isurum/736baf5fde1c8c3cc339058f9bdefa4b to your computer and use it in GitHub Desktop.
Regular Expression Route Constraints And Names in Laravel web.php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('users/{id}', function ($id) {
//
})->where('id', '[0-9]+');
Route::get('users/{username}', function ($username) {
//
})->where('username', '[A-Za-z]+');
Route::get('posts/{id}/{slug}', function ($id, $slug) {
//
})->where(['id' => '[0-9]+', 'slug' => '[A-Za-z]+']);
// Defining route names
// app/Http/routes.php
Route::get('members/{id}', [
'as' => 'members.show',
'uses' => 'MembersController@show'
]);
// view file
<a href="<?php echo route('members.show', ['id' => 14]); ?>">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment