这是我正在处理的路线(由apiResourceLaravel 的方法生成)。如您所见,有 1 或 2 个占位符。当我尝试 GET 时,我的问题就出现了anything/customers。它引发了这个异常:
Missing required parameters for [Route: json-api.customers.show] [URI: {tenant}/customers/{customer}].
除非我遗漏了一个明显的东西,否则路由器应该接受这个请求,因为anything/customers匹配{tenant}/customers.
我真的很感激任何有关这方面的帮助。提前致谢。
编辑:我添加此代码来回答评论,但我认为这对理解这个问题没有帮助(我正在实现一个基于 JSON:API 规范的包)。
protected function jsonApiResource()
{
return function (string $class, array $options = []) {
if ($routerMethod = $class::getRouterMethod()) {
$middleware = array_merge(
$options['middleware'] ?? [],
$class::getApiMiddlewares()
);
$as = $options['as'] ?? '';
$prefix = $class::getRouterPrefix();
$this->group(compact('middleware', 'as', 'prefix'), function ($router) use ($class, $routerMethod, $options) {
$alias = $class::getAlias();
$controller = $class::getControllerClass();
$router->{$routerMethod}(
$alias,
$controller,
Arr::only($options, ['only', 'except'])
);
foreach ($class::getRelationsRoutes() as $relationshipName => $relationshipMethods) {
$router->resourceRelationship(
$alias,
$relationshipName,
$controller,
$relationshipMethods
);
}
});
}
};
}
慕后森
慕码人8056858