当前位置:网站首页>Laravel document sorting 2. Route related
Laravel document sorting 2. Route related
2022-06-25 04:19:00 【Angry devil】
Preface :Laravel Document sorting , Only for record , Nothing else .
1、laravel Framework routing file :
app/Http/routes.php
Ps: The file will be App\Providers\RouteServiceProvider class load
2、 The most basic laravel Route is :
Route::get('/', function () {
return 'Hello World';
});
Route::post('foo/bar', function () {
return 'Hello World';
});
Route::put('foo/bar', function () {
//
});
Route::delete('foo/bar', function () {
//
});
Ps: Receive only url And a closure
3、 How to define how to respond to multiple http Routing of actions ?
Route::match(['get', 'post'], '/', function () {
return 'Hello World';
});
Ps: keyword match
4、 Corresponding multiple http Another way to write the route of actions :
Route::any('foo', function () {
return 'Hello World';
});
5、 Auxiliary functions generate routes
$url = url('foo');
6、 Configure parameters in the route
Route::get('user/{id}', function ($id) {
return 'User '.$id;
});
7、 Define any number of parameters in the route
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {
//
});
Ps:
A、 The parameters of the route will be placed in 「 Curly braces 」 Inside . When running a route , Parameters are passed by routing closed packets .
B、 Routing parameters cannot contain - character . Please underline (_) Replace .
8、 Define optional parameters in the route
Route::get('user/{name?}', function ($name = null) {
return $name;
});
Route::get('user/{name?}', function ($name = 'John') {
return $name;
});
Ps: Add... After the parameter name ?
9、 Format of restriction parameter in route
Route::get('user/{name}', function ($name) {
//
})
->where('name', '[A-Za-z]+');
Route::get('user/{id}', function ($id) {
//
})
->where('id', '[0-9]+');
Route::get('user/{id}/{name}', function ($id, $name) {
//
})
->where(['id' => '[0-9]+', 'name' => '[a-z]+']);
Ps: Use where Method
10、 Rules for globally defining routing parameters :
stay App\Providers\RouteServiceProvider Class boot Method :
/**
* Define your routing model bindings , Mode filter, etc .
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
$router->pattern('id', '[0-9]+');
parent::boot($router);
}
Ps: Note that once the schema is defined , Then all routes must follow this rule .
11、 How to alias a route
Route::get('user/profile', ['as' => 'profile', function () {
//
}]);、
Ps: as keyword
12、 Specify the route to the corresponding controller
Route::get('user/profile', [
'as' => 'profile',
'uses' => '[email protected]'
]);
13、 Another way to define a route :
Route::get('user/profile', '[email protected]')->name('profile');
Ps: call chaining name Method
14、 Set the same prefix for all routes in the group
Route::group(['as' => 'admin::'], function () {
Route::get('dashboard', ['as' => 'dashboard', function () {
// Route name is 「admin::dashboard」
}]);
});
15、 Named route generation urls
$url = route('profile');
$redirect = redirect()->route('profile');
Ps: Redirection can also be implemented .
16、 Named parameters define parameters , How to generate urls
Route::get('user/{id}/profile', ['as' => 'profile', function ($id) {
//
}]);
$url = route('profile', ['id' => 1]);
Ps: Give to the route Method .
边栏推荐
- Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00005
- LeetCode 剑指Offer II 091 粉刷房子[动态规划] HERODING的LeetCode之路
- 论文阅读《LSD-SLAM: Large-Scale Direct Monocular SLAM》
- Flutter FittedBox组件
- Crawler grabs the data of Douban group
- Hello CTP (III) - CTP quotation API
- Hello CTP (V) -- CTP position calculation
- 数学分析_笔记_第3章:极限
- 1280_C语言求两个无符号整形的平均值
- Numpy NP tips: use OpenCV to interpolate and zoom the array to a fixed shape cv2 resize(res, dsize=(64, 64), interpolation=cv2. INTER_ CUBIC)
猜你喜欢
UCLA | 用于黑盒优化的生成式预训练
Lecture record: data processing methods and applications of various spatial geodetic techniques
地方/園區產業規劃之 “ 如何進行產業定比特 ”
《Missing Parts》NFT 作品集第 5 系列上线 The Sandbox 市场平台
讲座记录《惯性导航的新应用——惯性测量》
WMS仓储管理系统的使用价值,你知道多少
1280_C语言求两个无符号整形的平均值
Leetcode points to the leetcode road of offering II 091 house painting [dynamic planning] heroding
Crawler crawls Sina Weibo data
数学分析_笔记_第3章:极限
随机推荐
Hot and cold, sweet and sour, want to achieve success? Dengkang oral, the parent company of lengsuanling, intends to be listed on the main board of Shenzhen Stock Exchange
【openwrt】推荐一个国内开发的openwrt的版本,iStoreOS简介,非常好用,主要是做了一些优化。解决了汉化的问题。
DAP data scheduling function improvement description
Mysql的order by
Zoran community
2D 照片变身 3D 模型,来看英伟达的 AI 新“魔法”!
代表多样性的彩色 NFT 系列上线 The Sandbox 市场平台
如何绘制产业招商地图
PHP code audit 1 - php Ini
[harmony OS] [arkui] ETS development graphics and animation drawing
Color NFT series representing diversity launched on the sandbox market platform
警惕超范围采集隐私-移动APP违规十宗罪
acmStreamOpen返回值问题
数字时代的“文艺复兴”?起底数字藏品,让人欢喜让人愁
Changsha's "talent seeking": "making efforts" and "making practical moves" go hand in hand, "rapid development" and "slow life" go hand in hand
WMS仓储管理系统的使用价值,你知道多少
Shutter fittedbox component
LeetCode 剑指Offer II 091 粉刷房子[动态规划] HERODING的LeetCode之路
练习:仿真模拟福彩双色球——中500w巨奖到底有多难?跑跑代码就晓得了。
1. first knowledge of chromatic harmonica