基本路由
Route::get(‘/user‘, ‘UserController@index‘);
可用的路由方法
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::redirect(‘/here‘, ‘/there‘, 301);
视图路由
Route::view(‘/welcome‘, ‘welcome‘); Route::view(‘/welcome‘, ‘welcome‘, [‘name‘ => ‘Taylor‘]);
路由参数
Route::get(‘user/{id}‘, function ($id) { return ‘User ‘.$id; });
Route::get(‘posts/{post}/comments/{comment}‘, function ($postId, $commentId) {
//
});
还有很多的路由方式,可以查阅官方手册
路由在实际项目中应用
场景一:多个模块路由部署 (Admin,Index,Api)
场景二:路由与控制器之间的传参
原文:https://www.cnblogs.com/wesky/p/10443206.html