Last active
June 16, 2017 15:58
-
-
Save isurum/736baf5fde1c8c3cc339058f9bdefa4b to your computer and use it in GitHub Desktop.
Regular Expression Route Constraints And Names in Laravel web.php
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
/* | |
|-------------------------------------------------------------------------- | |
| 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