Skip to content

Commit 03af923

Browse files
author
qiang.sun
committed
路由入门
1 parent 4c437b4 commit 03af923

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

routes/web.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,23 @@
1414
Route::get('/', function () {
1515
return "Hello, World!";
1616
});
17+
18+
Route::get('user/{id?}', function ($id = 1) {
19+
return "用户ID: " . $id;
20+
})->name('user.profile');
21+
22+
Route::get('page/{id}', function ($id) {
23+
return '页面ID: ' . $id;
24+
})->where('id', '[0-9]+');
25+
26+
Route::get('page/{name}', function ($name) {
27+
return '页面名称: ' . $name;
28+
})->where('username', '[A-Za-z]+');
29+
30+
Route::get('page/{id}/{slug}', function ($id, $slug) {
31+
return $id . ':' . $slug;
32+
})->where(['id' => '[0-9]+', 'slug' => '[A-Za-z]+']);
33+
34+
Route::get('test', function () {
35+
return route('user.profile', [100]);
36+
});

0 commit comments

Comments
 (0)