laravel 路由规则及小坑

laravel 5.8.3的web路由在 /route/web.php中;

//基础路由

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

//基础路由

 Route::get('basic1', function() {
    return 'Helloworld';
}); 

//基础路由

 Route::post('basic2', function () {
    return 'basic2';
}); 

//多请求路由

 Route::match(['post', 'get'], 'match', function() {
    return '667896876';
}); 

路由参数 及 路由参数验证(where)
//路由参数type1

 Route::get('user/{id}', function ($id) {
    return 'User-'.$id;
}); 

//路由参数type2

 Route::get('user/{xxx?}', function ($xxx = '123') {
    return 'User-xxx-'.$xxx;
})->where('xxx', '[A-Za-z]+');

//路由参数type3

Route::get('user/{id}{xxx?}', function ($id, $xxx = '123') {
    return 'User-id-'.$id.'-name-'.$xxx;
})->where(['id' => '[0-9]+', 'xxx' => '[A-Za-z]+']); */

//路由别名

 方法1:Route::get('user/member-center', ['as' => 'center', function () {
    return route('center'); //返回路由原名
}]); 
方法2:Route::any('member/info', [
	'uses' => 'MemberController@info',
	'as' => 'memberinfo'
]);

//路由群组

     Route::group(['prefix' => 'member'], function () {
        Route::get('user/center', ['as' => 'center', function () {
            return route('center');
        }]);

    Route::any('multy2', function () {
        return 'member-multy2';
    });
}); 

//路由中输出视图

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

小坑:如果删除框架自带的基础路由,会导致框架首页无妨访问哦!!!
//基础路由

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

//废弃的路由函数
Route::controller(); //5.2已废弃

你可能感兴趣的:(laravel)