基本路由
Route::get('hello', function () {
return 'Hello, Laravel';
});
Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
Route::match(['get', 'post'], '/', function () {
});
Route::any('foo', function () {
});
路由参数
- 使用花括号包裹
- 路由参数不能包含 - 字符, 需要的话可以使用 _ 替代
Route::get('user/{id}', function ($id) {
return 'User '.$id;
});
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {