当前位置:网站首页>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
}]);
边栏推荐
- Record in-depth learning - some bug handling
- These 18 websites can make your page background cool
- leetcode 10. Regular expression matching regular expression matching (difficult)
- 2022年机修钳工(高级)考试题模拟考试题库模拟考试平台操作
- 49. Grouping of alphabetic ectopic words: give you a string array, please combine the alphabetic ectopic words together. You can return a list of results in any order. An alphabetic ectopic word is a
- asp. Net read TXT file
- [public class preview]: basis and practice of video quality evaluation
- redis6主从复制及集群
- zabbix 监控
- Summit review | baowanda - an integrated data security protection system driven by compliance and security
猜你喜欢
[cloud resources] what software is good for cloud resource security management? Why?
Binder communication process and servicemanager creation process
Catch all asynchronous artifact completable future
研究生可以不用学英语?只要考研英语或六级分数高!
龙芯派2代烧写PMON和重装系统
Self built shooting range 2022
laravel-dompdf导出pdf,中文乱码问题解决
Jetpack Compose入门到精通
华为推送服务内容,阅读笔记
Godson 2nd generation burn PMON and reload system
随机推荐
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
运筹说 第68期|2022年最新影响因子正式发布 快看管科领域期刊的变化
龙芯派2代烧写PMON和重装系统
zabbix 监控
Record in-depth learning - some bug handling
UE源码阅读[1]---由问题入手UE中的延迟渲染
荐号 | 有趣的人都在看什么?
[public class preview]: basis and practice of video quality evaluation
RK3566添加LED
MMSeg——Mutli-view时序数据检查与可视化
The real king of caching, Google guava is just a brother
The development of speech recognition app with uni app is simple and fast.
Ueditor + PHP enables Alibaba cloud OSS upload
redis6事务和锁机制
Usage, installation and use of TortoiseSVN
PostgreSQL Usage Summary (PIT)
The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
链表(简单)
ELK 企业级日志分析系统
Laravel generate entity