当前位置:网站首页>Laravel5.1 Routing - routing packets
Laravel5.1 Routing - routing packets
2022-07-07 16:21:00 【Full stack programmer webmaster】
What are the benefits of routing packets ?
Sometimes A lot of routes have something in common , For example, they all use a middleware ( Write in two days ) Or the prefix is the same , Avoid code duplication We can divide them into a group .
1 Which attributes can be shared by routing packets ?
- middleware middleware.
- The namespace of the controller namespace.
- subdomain domain
- Route prefix
1.1 middleware
About middleware K I haven't written notes about , Let's talk about it briefly Middleware is to verify something after receiving the request or verify something after corresponding , such as Laravel Self contained Auth middleware Is to verify whether the user has logged in , If the user is not logged in , Then it will automatically jump to the login page , We don't need to implement this logic at all .
All right. Return to the right topic , Let's see how to write routing packets :
/** * This is a routing packet /user and /user/profile Will use auth middleware . */ Route::group(['middleware' => 'auth'], function (){ Route::get('/user', function (){ }); Route::get('/user/profile', function (){ }); });1.2 Route prefix
/** * What about the routing prefix That is to say, all routing paths in this packet are prefixed */ Route::group(['prefix' => 'admin'], function (){ /** * Routing packets can be nested */ Route::group(['middleware' => 'auth'], function (){ /** * This route not only uses auth middleware , And added admin Prefix , We go through /admin/user Ability to visit */ Route::get('/user', function (){ }); Route::get('/user/profile', function (){ }); }); /** * The access path is :/admin */ Route::get('/', function (){ });; });1.3 subdomain
/** * For example, we can input larger To access the route , In the sub route, you can set larger Fetch . */ Route::group(['domain' => '{account}.myapp.com'], function () { Route::get('user/{id}', function ($account, $id) { // }); });Be careful : If you want to test the subdomain name, you need to use homestand To set your domain name . Be careful : If you want to test the subdomain name, you need to use homestand To set your domain name .
1.4 Namespace
This is another point that has not been written This contains the contents of the controller , Let's look at the examples first I'll learn the controller tomorrow It's time to take notes .
/** * As long as the namespace is specified , Then all controllers used in the sub route are located in App\Http\Controller\Admin Under this namespace . */ Route::group(['namespace' => 'Admin', 'prefix' => 'admin'], function(){ /** * Actually HomeController stay App\Http\Controller\Admin Under this namespace . */ Route::get('/', '[email protected]'); });1.5 Group naming
add , In the previous basic article, we learned to name routes , Can the grouping be named ,Yo Man.. Certainly. :
/** * Just like normal routing Also use as But the first letter should be capitalized followed by two colons It represents a group If you write like this We can go through route('Admin::index') Way to find it */ Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'as' => 'Admin::'], function(){ Route::get('/', ['as' => 'index','uses' => '[email protected]']); });Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/113173.html Link to the original text :https://javaforall.cn
边栏推荐
- Common training data set formats for target tracking
- You Yuxi, coming!
- How can laravel get the public path
- Shader basic UV operations, translation, rotation, scaling
- SPI master RX time out interrupt
- 统计学习方法——感知机
- MySQL中, 如何查询某一天, 某一月, 某一年的数据
- 融云斩获 2022 中国信创数字化办公门户卓越产品奖!
- 【HCSD大咖直播】亲授大厂面试秘诀-简要笔记
- Odoo集成Plausible埋码监控平台
猜你喜欢

模仿企业微信会议室选择

深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)

Plate - forme de surveillance par étapes zabbix

航運船公司人工智能AI產品成熟化標准化規模應用,全球港航人工智能/集裝箱人工智能領軍者CIMC中集飛瞳,打造國際航運智能化標杆

分步式监控平台zabbix

Dotween -- ease function

How does geojson data merge the boundaries of regions?

MySQL数据库基本操作-DQL-基本查询
![[flower carving experience] 15 try to build the Arduino development environment of beetle esp32 C3](/img/8f/ca9ab042916f68de7994d9f2124da9.jpg)
[flower carving experience] 15 try to build the Arduino development environment of beetle esp32 C3

Xcode Revoke certificate
随机推荐
喜讯!科蓝SUNDB数据库与鸿数科技隐私数据保护管理软件完成兼容性适配
ThinkPHP URL 路由简介
MySQL数据库基本操作-DQL-基本查询
Tragedy caused by deleting the console statement
Step by step monitoring platform ZABBIX
A link opens the applet code. After compilation, it is easy to understand
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
修改配置文件后tidb无法启动
Limit of total fields [1000] in index has been exceeded
删除 console 语句引发的惨案
Leetcode-136- number that appears only once (solve with XOR)
Leetcode-136-只出现一次的数(用异或来解答)
logback.xml配置不同级别日志,设置彩色输出
What about the pointer in neural network C language
神经网络c语言中的指针是怎么回事
How can laravel get the public path
The differences between exit, exit (0), exit (1), exit ('0 '), exit ('1'), die and return in PHP
leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
Three. JS introductory learning notes 18: how to export JSON files with Blender
通知Notification使用全解析