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) {

    //

});

猜你喜欢

转载自www.cnblogs.com/CWJDD/p/11463178.html
今日推荐