laravel - Laravel 路由不适用于子文件夹
问题描述
使用从 4.2 迁移的 Laravel 5 现在 laravel 5 安装在子文件夹“abc”中,我必须为每条路线编写 abc/warehouse 吗?以前是 /warehouse。我想在子目录 abc 中使用所有现有路由,例如 /warehouse。
我在 localhost xampp 上,端口为 81。 http://localhost:81/warehouse
这里有快速解决方案的任何人
解决方案
You use prefix
when defining routes:
Route::prefix('abc')->group(...)
Route::prefix('abc')->group(function () {
Route::get('warehouse', function () {
// Matches The "/abc/warehouse" URL
});
});
Ideally you should do it in the RouteServiceProvider
Route::middleware('web')
->prefix('abc')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
This way everything in the routes file is prefixed and you dont need the extra group wrapping.
Here's the example from the 5.0 docs:
Route::group(['prefix' => 'admin'], function() {
Route::get('users', function() {
// Matches The "/admin/users" URL
});
});
推荐阅读
- android - 在 Kotlin 的底部片段中添加子片段
- r - 如果语句必须采用这种格式,为什么要使用 R?
- python - 填写分类列的缺失值
- javascript - React Native:点击 ScrollView 组件内的子组件触发最后一项的 onPress 事件
- php - PHP Group Array 按函数对值的结果
- python - 在 Python 中创建具有多列的运行总计
- artificial-intelligence - 使用热图核心图像探索数据
- javascript - 如何在svg纹理threejs之上添加织物js纹理
- python - currentIndexChanged 和 currentTextChanged PyQt5 有什么区别
- entity-framework-core - 无法跟踪“Entity”类型的实体,因为其主键属性“Id”为空