laravel框架——路由

基本路由:  

Route::get('/', function () {
    return view('welcome');
});

Route::post('/', function () {
    return view('welcome');
});

 

路由前缀:

Route::group(['prefix'=>'wechat'],function (){
    Route::get('/',function (){
        return 'wechat根目录';
    });
});

 

带参数的路由:

//必须带上参数
Route::get('/edit/{id}',function ($id){
});
//可以不带参数,但是必须有默认值
Route::get('/edit/{id?}',,function ($id=1){
});
//可以跟上where,使用正则去匹配参数
Route::get('/edit/{id}',function ($id){
})->where('id', '[0-9]+');
Route::get('user/{id}/{name}', function ($id, $name) {
})->where(['id' => '[0-9]+', 'name' => '[a-z]+']);

  

posted @ 2016-10-17 11:44  偏执Dog  阅读(785)  评论(0编辑  收藏  举报