Home  >  Article  >  PHP Framework  >  Introduction to code examples of routing in laravel

Introduction to code examples of routing in laravel

不言
不言Original
2018-08-03 13:47:042825browse

This article introduces to you the code examples of routing in laravel. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Introduction to routing

Convert the request to the program

Function: mapping between url and program

Request method post get put patch delete

eg:

//get请求
Route::get('basic1',function(){
    return 'hello world';
});
//多种请求
//指定请求方式
Route::match(['get','post'],'match',function(){
    return 'match';
});
//不指定
Route::any('any',function(){
    return 'any';
});
//路由参数
Route::get('user/{id}',function($id){
    return 'User-'.$id;
});
Route::get('user/{id?}/{name?}',function($id,$name){
    return 'User-name-'.$name;
})->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']);
//请求的路由 http://localhost/public/user/1/w
//路由的别名
Route::get('user/member-center',['as'=>'center',function(){
    return route('center');
}]);
//路由群组
//prefix 前缀
Route::group(['prefix'=>'member'],function(){
    Route::get('user/center',['as'=>'center',function(){
        return route('center');
    }]);
    Route::get('user/person',['as'=>'person',function(){
        return route('person');
    }]);
});
//路由中输出view
Route::get('view', function () {
    return view('welcome'); 
});

The above is the entire content of this article.

Related recommendations:

How to customize the analysis of log behavior in Laravel5.5

View in laravel5.5 framework How to share data between views? Two ways to share data between views (with code)

The above is the detailed content of Introduction to code examples of routing in laravel. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn