php - Laravel 路由与 Application 在子目录中的位置不匹配
问题描述
我在子目录中有我的 Laravel 应用程序:
https://www.example.com/subdirectory/api
这意味着对 API 的请求是这样完成的:
// GET https://www.example.com/subdirectory/api/user/1
// Meanwhile in api.php
Route::get('/user/{id}', 'controllerName@methodName');
并按预期返回。
但是,当尝试使用$this->get()
测试用例上的方法设置这些端点的功能测试时,我的路由不匹配。这似乎正在发生,因为整个子目录结构都包含在最终路由中:
// In Test
$response = $this->get('/user/2');
// In api.php this no longer matches
Route::get('/user/{id}', 'controllerName@methodName');
// But this does
Route::get('/subdirectory/api/user/{id}', 'controllerName@methodName');
json
基本上,在使用任何/ get
/post
等方法从测试中查询之前,路由似乎工作得非常好。请求中的文字字符串 URL 完全没问题(没有重复的子目录等)。
为什么我的路由匹配真实查询而不是这些测试查询?
- 我
APP_URL
在我的所有 .env 文件中都正确设置 - 我已经尝试在测试 json 调用中完全描述 URL
- 我试过有/没有前导斜杠
解决方案
推荐阅读
- java - 多次运行 .jar 文件
- c++ - 如果 c++ 类模板成员函数不使用模板参数,如何将它们放入 cpp 文件中?
- node.js - 将套接字连接保存到 JSOn
- c - 输入文本文件的结果 int 值不存储在数组中。C语言
- python - 在 Django 的 RegexValidator 中引用搜索组
- c# - 表单身份验证和无限重定向?
- angular - 如何从 Angular 属性绑定加载框架资产
- nlog - Nlog / event-properties:如何提示 NLog 从最终日志条目中忽略/跳过空/空属性
- python - if语句中的while循环?
- javascript - ts:导出默认功能组件