当前位置:网站首页>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
}]);
边栏推荐
- The development of speech recognition app with uni app is simple and fast.
- MySQL if else use case use
- Source code analysis of etcd database -- peer RT of inter cluster network layer client
- leetcode 10. Regular Expression Matching 正则表达式匹配 (困难)
- How to apply the updated fluent 3.0 to applet development
- "Baidu Cup" CTF competition in September, web:upload
- The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
- [notes of in-depth study paper]transbtsv2: wider instead of deep transformer for medical image segmentation
- 真正的缓存之王,Google Guava 只是弟弟
- Pancake Bulldog robot V2 (code optimized)
猜你喜欢
Attack and defense world crypto WP
面试官灵魂拷问:为什么代码规范要求 SQL 语句不要过多的 join?
Data Lake (VII): Iceberg concept and review what is a data Lake
这18个网站能让你的页面背景炫酷起来
Win10——轻量级小工具
Introduction to Chapter 8 proof problem of njupt "Xin'an numeral base"
Laravel framework operation error: no application encryption key has been specified
龙芯派2代烧写PMON和重装系统
stm32逆向入门
When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.
随机推荐
[public class preview]: basis and practice of video quality evaluation
js 从一个数组对象中取key 和value组成一个新的对象
The development of speech recognition app with uni app is simple and fast.
Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
What is information security? What is included? What is the difference with network security?
Zhubo Huangyu: it's really bad not to understand these gold frying skills
嵌入式软件架构设计-消息交互
Binder communication process and servicemanager creation process
asp. Net read TXT file
redis6数据类型及操作总结
Wonderful express | Tencent cloud database June issue
Resttemplate details
Flutter 3.0更新后如何应用到小程序开发中
With 4 years of working experience, you can't tell five ways of communication between multithreads. Dare you believe it?
Kotlin协程利用CoroutineContext实现网络请求失败后重试逻辑
Catch all asynchronous artifact completable future
asp.net 读取txt文件
Ordering system based on wechat applet
Elfk deployment
About the problem and solution of 403 error in wampserver