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

Introduction to code examples of routing in laravel

不言
Release: 2021-05-28 17:33:10
Original
2891 people have browsed it

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
Copy after login
//路由的别名
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'); 
});
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template