当前位置:网站首页>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 .
边栏推荐
- SQL, CTE, flg case problems
- Trading system development (IV) - trading counter system
- 学习码 滚动码 固定码 有什么区别重码数,编码容量滚动码的原理
- How much do you know about the use value of WMS warehouse management system
- 【LeetCode】148. 排序链表
- WMS仓储管理系统的使用价值,你知道多少
- 代表多样性的彩色 NFT 系列上线 The Sandbox 市场平台
- Development of trading system (VI) -- HFT high frequency trading
- 虽然传统意义上的互联网早已不复存在,但这并不代表互联网早已消失不再
- How to use ide to automatically sign and debug Hongmeng application
猜你喜欢

NFT Insider #63:The Sandbox与时代杂志达成合作,YGG成立西班牙subDAO

Cesium drag 3D model

NFT insider 63: the sandbox reached a cooperation with Time magazine, and YGG established Spain's subdao

地方/園區產業規劃之 “ 如何進行產業定比特 ”

"Grammar sugar" -- my new programming knowledge

Cesium 加载显示热力图

95% 程序员都在这里摸鱼……

5 key indicators of SEO: ranking + traffic + session + length of stay + bounce rate

"Renaissance" in the digital age? The bottom digital collection makes people happy and sad

"Comment positionner l'industrie" dans la planification industrielle locale / parc
随机推荐
Changsha's "talent seeking": "making efforts" and "making practical moves" go hand in hand, "rapid development" and "slow life" go hand in hand
acmStreamOpen返回值问题
Qt编译数据库插件通用步骤说明
Coinlist queuing tutorial to improve the winning rate
mysql的tinyint字段类型判断的疑惑
冷热酸甜、想成就成?冷酸灵母公司登康口腔欲在深交所主板上市
Leetcode points to the leetcode road of offering II 091 house painting [dynamic planning] heroding
SQL, CTE, flg case problems
Hello CTP (III) - CTP quotation API
Serious PHP defects can lead to rce attacks on QNAP NAS devices
Crawler crawls Sina Weibo data
升级cmake
Development of trading system (VI) -- HFT high frequency trading
PHP code audit 2 - these functions must be known and understood
Intel 13th generation core showed its true colors for the first time: 68mb cache improved significantly
虽然传统意义上的互联网早已不复存在,但这并不代表互联网早已消失不再
讲座记录《捷联惯导解算的历史及发展》
Zoran community
Development of trading system (x) -- fix agreement
client-go gin的简单整合十一-Delete