Laravel 路由
Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function () { Route::group(['prefix' => 'login'], function () { // 登录页面 Route::get('index', 'LoginController@index')->middleware('admin.login'); // 退出 Route::get('logout', 'LoginController@logout'); }); });
生成的url地址: localhost/admin/login/index
重定向路由
Route::redirect('/here', '/there', 301);
视图路由
Route::view('/welcome', 'welcome', ['name' => 'Taylor']);
view
方法有三个参数,其中前两个是必填参数,分别是 URL 和视图名称。第三个参数选填,可以传入一个数组,数组中的数据会被传递给视图
路由参数
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) { //});
localhost/posts/1/comments/2
可选参数
Route::get('user/{name?}', function ($name = 'John') { return $name;});
localhost/user/john 或者 localhost/user