一些基础例子
1.1 基础例子
// 可以 /home 也可以 home
Route::get('/home', function () {
return 'hello home';
});
/home
1.2 请求参数 请求方式 。 可以 ::post put delete
还可以::match['get','post']
路由参数
//参数必填
Route::get("/user/{id}", function ($id){
return 'user:'.$id;
});
//可选参数
Route::get("/test4/{id?}", function ($id=5){
return 'user:'.$id;
});
路由别名.
Route::get('/home', function () {
return 'hello home';
})->name('home2');
路由群组,
外面套一层即可。
Route::group(['prefix' => 'admin'],function(){
Route::get('/test', function () {
return 'hello admin test';
});
//...
});