1Route::match(['get', 'post'], '/', function () {
2 //
3});
4
5Route::any('/', function () {
6 //
7});
1Route::get('user/profile', [UserProfileController::class, 'show'])->name('profile');
1// You can make a parameter optional by placing a '?' after the parameter name.
2// Make sure to give the route's corresponding variable a default value:
3Route::get('user/{name?}', function ($name = null) {
4 return $name;
5});
6
7Route::get('user/{name?}', function ($name = 'John') {
8 return $name;
9});
1Route::get('user/{name?}', function ($name = null) {
2 return $name;
3});
4
5Route::get('user/{name?}', function ($name = 'John') {
6 return $name;
7});
1Route::get('/user/{name}', function ($name) {
2 //
3})->where('name', '[A-Za-z]+');
4
5Route::get('/user/{id}', function ($id) {
6 //
7})->where('id', '[0-9]+');
8
9Route::get('/user/{id}/{name}', function ($id, $name) {
10 //
11})->where(['id' => '[0-9]+', 'name' => '[a-z]+']);
12
13reference : https://laravel.com/docs/8.x/routing#parameters-regular-expression-constraints