Laravel中的路由2

访问控制器中的方法

Route::get('/user', 'UsersController@index');

重定向路由

Route::redirect('/here', '/there', 301);

 

视图路由

Route::view('/welcome', 'welcome');

 

向路由中传入一个数组

数组中的数据可以传递给视图

Route::view('/welcome', 'welcome', ['name' => 'Taylor']);

URL 中捕获用户的 ID,可以通过定义路由参数来执行

Route::get('user/{id}', function ($id) {

    return 'User '.$id;

});

也可以根据需要在路由中定义多个参数:

Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {

    //

});

 

posted @ 2019-09-05 10:00  CWJDD  阅读(150)  评论(0编辑  收藏  举报