当前位置:网站首页>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
边栏推荐
- 目标跟踪常见训练数据集格式
- Vs tool word highlight with margin
- Use moviepy Editor clips videos and intercepts video clips in batches
- hellogolang
- Multiplication in pytorch: mul (), multiply (), matmul (), mm (), MV (), dot ()
- Logback logging framework third-party jar package is available for free
- 过度依赖补助,大客户收款难,冲刺“国产数据库第一股”的达梦后劲有多足?
- How can laravel get the public path
- U3D_ Infinite Bessel curve
- Leetcode-136- number that appears only once (solve with XOR)
猜你喜欢
Leetcode-231-2的幂
Enterprise log analysis system elk
【Android -- 数据存储】使用 SQLite 存储数据
What are compiled languages and interpreted languages?
Xcode Revoke certificate
Numpy --- basic learning notes
Dotween -- ease function
Logback日志框架第三方jar包 免费获取
分步式监控平台zabbix
Three. JS introductory learning notes 19: how to import FBX static model
随机推荐
强化实时数据管理,英方软件助力医保平台安全建设
Laravel 服务提供者实例教程 —— 创建 Service Provider 测试实例
Migration and reprint
Numpy --- basic learning notes
企业级日志分析系统ELK
Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping
安科瑞电网智能化发展的必然趋势电力系统采用微机保护装置是
Logback logging framework third-party jar package is available for free
华东师大团队提出,具有DNA调控电路的卷积神经网络的系统分子实现
AE learning 01: AE complete project summary
Description of vs common shortcut keys
Vs tool word highlight with margin
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
模仿企业微信会议室选择
leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
MySQL中, 如何查询某一天, 某一月, 某一年的数据
Unity3D_ Class fishing project, control the distance between collision walls to adapt to different models
three.js打造酷炫下雪效果
laravel构造函数和中间件执行顺序问题
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()