Simple Example of Laravel Framework Routing Management
- 2021-12-09 08:34:48
- OfStack
This article illustrates the routing management of Laravel framework. Share it for your reference, as follows:
Output view in routing
Route::get('/', function () {
return view('welcome');
});
get Routing Request
Route::get('get',function(){
return 'get Routing request ';
});
post Routing Request
Route::post('post',function(){
return 'post Request ';
});
Multi-route request
Route::match(['get','post'],'match',function(){
return ' Multi-route request ';
});
Arbitrary routing request
Route::any('any',function(){
return ' Arbitrary routing request ';
});
Routing parameters
Route::get('user/{id}',function($id){
return 'user-id-'.$id;
});
Default value of routing parameters
Route::get('user/{name?}',function($name = 'yxh'){
return 'user-name-'.$name;
});
Regular verification of routing parameters
Route::get('user/{id}/{name?}',function($id,$name = 'yxh'){
return 'user-id-'.$id.'-name-'.$name;
})->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']);
Routing alias
Route::get('user/member-center',['as'=>'center',function(){
return route('center');
}]);
Routing group
Route::group(['prefix'=>'member'],function(){
// Routing alias
Route::get('user/member-center',['as'=>'center',function(){
return route('center');
}]);
// Arbitrary routing request
Route::any('any',function(){
return ' Arbitrary routing request ';
});
});
Output view in routing
Route::get('get',function(){
return 'get Routing request ';
});
0
Correlation controller
Route::get('get',function(){
return 'get Routing request ';
});
1
More readers interested in Laravel can check the topics of this site: "Introduction and Advanced Tutorial of Laravel Framework", "Summary of Excellent Development Framework of php", "Introduction Tutorial of php Object-Oriented Programming", "Introduction Tutorial of php+mysql Database Operation" and "Summary of Common Database Operation Skills of php"
I hope this article is helpful to the PHP programming based on Laravel framework.