2 回答

TA貢獻1802條經驗 獲得超5個贊
路由器很難通過任一側的變量來確定。在第一個/像something/{tenant}/customers. 但是,錯誤的原因很可能是根據您的路由列表到達路由器的第一個 GET 路徑是:
{tenant}/customers/{customer}
因為這是第一個,Laravel預計會有一個客戶變量進來。如果將此行放在更高的位置,則不會每次都期望變量。所以:
{tenant}/customers/{customer}
{tenant}/customers/
這應該會有所幫助......但它可能不是由于兩邊的通配符 - 你必須測試。
如果您將這些設置為 a resource,我建議您將它們分解為單獨的路由方法進行測試

TA貢獻1803條經驗 獲得超6個贊
終于在三天后,我找到了來源,異常消息誤導了我。
/**
* Get links to fetch the model or one of its relationships.
*
* @param string|null $relationshipName
* @return array
*/
public function getApiLinks(string $relationshipName = null)
{
$urlGenerator = app()->make('url');
$identifiers = $this->getApiIdentifiers();
if ($relationshipName) {
return [
'self' => $urlGenerator->jsonApiRelationship($identifiers['type'], $identifiers['id'], $relationshipName, 'index'),
'related' => $urlGenerator->jsonApiRelationship($identifiers['type'], $identifiers['id'], $relationshipName, 'related')
];
}
return [
'self' => $urlGenerator->route(
'json-api.'.$identifiers['type'].'.show',
[ Str::singular($identifiers['type']) => $identifiers['id'] ]
];
問題來自返回時的 URL 生成,任何額外的 URL 占位符都不會包含在數組中,順便說一下導致此消息。
有了這個修復,它現在可以工作了:
/**
* Get links to fetch the model or one of its relationships.
*
* @param string|null $relationshipName
* @return array
*/
public function getApiLinks(string $relationshipName = null)
{
$urlGenerator = app()->make('url');
$identifiers = $this->getApiIdentifiers();
$otherParams = $urlGenerator->getRequest()->route()->parameters();
if ($relationshipName) {
return [
'self' => $urlGenerator->jsonApiRelationship($identifiers['type'], $identifiers['id'], $relationshipName, 'index', $otherParams),
'related' => $urlGenerator->jsonApiRelationship($identifiers['type'], $identifiers['id'], $relationshipName, 'related', $otherParams)
];
}
return [
'self' => $urlGenerator->route(
'json-api.'.$identifiers['type'].'.show',
array_merge(
$otherParams,
[ Str::singular($identifiers['type']) => $identifiers['id'] ]
)
)
];
}
無論如何感謝您的幫助!
- 2 回答
- 0 關注
- 123 瀏覽
添加回答
舉報