当前位置:网站首页>Routing in laravel framework
Routing in laravel framework
2022-07-05 13:49:00 【Weichi Begonia】
Common methods in routing
laravel The routes in the framework are defined in routes/web.php in , Commonly used Route Class get/ any/ match Method to define the route , among any/match All support multiple request modes ,group Method can be used to define routing groups , such as :
Route::get('integration', function () {
return "hello world";
});In the above code get Method requires two parameters , One is url Address (integration The front frame will be automatically added and defined in xampp Medium url Address ), One is function, Inside is the value we need to return or view.
If it is view, It can be defined as this :
Route::get('/', function () {
return view('welcome');
});laravel Common methods defined by the middle road :
1. get Method : ditto
2. any Method ( Multi route request ): That is, this route can be triggered in any way , such as :
Route::any('multi2', function(){
return "multi2";
});3. match Method ( Multi route request ):
Route::match(['get', 'post'], 'multi1', function(){
return 'multi1'; // This route supports get/post Way to trigger
});3. routing group
Route::group(['prefix'=>"member"], function(){
// The following routes will all have member Prefix
Route::get('user/center', ['as'=>'center', function(){
return route('center');
}]);
Route::any('multy2', function(){
return "group-multi2";
});
});How to add parameters to a route ?- The wonderful use of braces {}
Route::get("user/{id}/{name?}", function($id,$name=null){
return "User-yingkun-".$id."-".$name;
});How to add some parameter restrictions to the route ? -- Use where Method
Route::get("user/{id}/{name}", function($id, $name){
return "User-" . $id . "-name-" . $name;
})->where(["id"=>"\d+", "name"=>"[A-Za-z]+"]);Routing alias
Route::get("user/member-center", ["as"=>"center", function(){
// return "member-center";
return route('center'); // route The function is used to generate the specified route url Address of the
}]);
边栏推荐
- MySQL if else use case use
- Elk enterprise log analysis system
- Jasypt configuration file encryption | quick start | actual combat
- Zhubo Huangyu: these spot gold investment skills are not really bad
- STM32 reverse entry
- Basic characteristics and isolation level of transactions
- Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
- Laravel框架运行报错:No application encryption key has been specified
- 南理工在线交流群
- UE源码阅读[1]---由问题入手UE中的延迟渲染
猜你喜欢

不知道这4种缓存模式,敢说懂缓存吗?

Elfk deployment

redis6事务和锁机制

Attack and defense world web WP

laravel-dompdf导出pdf,中文乱码问题解决

Could not set property ‘id‘ of ‘class XX‘ with value ‘XX‘ argument type mismatch 解决办法

真正的缓存之王,Google Guava 只是弟弟

面试官灵魂拷问:为什么代码规范要求 SQL 语句不要过多的 join?
![[South China University of technology] information sharing of postgraduate entrance examination and re examination](/img/a8/41e62a7a8d0a2e901e06c751c30291.jpg)
[South China University of technology] information sharing of postgraduate entrance examination and re examination

Huawei push service content, read notes
随机推荐
Embedded software architecture design - message interaction
aspx 简单的用户登录
uplad_ Labs first three levels
leetcode 10. Regular expression matching regular expression matching (difficult)
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
Jetpack compose introduction to mastery
redis6数据类型及操作总结
链表(简单)
Jasypt configuration file encryption | quick start | actual combat
"Baidu Cup" CTF competition in September, web:upload
Wonderful express | Tencent cloud database June issue
NFT value and white paper acquisition
【云资源】云资源安全管理用什么软件好?为什么?
Mmseg - Mutli view time series data inspection and visualization
[cloud resources] what software is good for cloud resource security management? Why?
荐号 | 有趣的人都在看什么?
Laravel框架运行报错:No application encryption key has been specified
2022司钻(钻井)考试题库及模拟考试
Win10 - lightweight gadget
Source code analysis of etcd database -- peer RT of inter cluster network layer client