您好,我尝试使用laravel和nuxt制作应用程序,但无法显示模型中的关系。主要型号有:
论坛
laravel的控制器:
public function index()
{
return new ForumResource(Forum::where("parent_id", null)
->with("last.topic", "last.author")
->get());
}
api的结果:
"data": [
{
"id": 1,
"deleted_at": null,
"name": "Opera/8.21 (Windows NT 5.01; en-US) Presto/2.11.178 Version/10.00",
"slug": "opera821-windows-nt-501-en-us-presto211178-version1000",
"content": "Ut non ut totam et et.",
"last_id": 1,
"created_at": "2020-03-29T16:35:45.000000Z",
"updated_at": "2020-03-29T16:35:45.000000Z",
"_lft": 1,
"_rgt": 1,
"parent_id": null,
"last": {
"id": 1,
"created_at": "2020-03-29T16:50:40.000000Z",
"updated_at": "2020-03-29T16:50:40.000000Z",
"deleted_at": null,
"author_id": 10,
"topic_id": 6,
"content": "Ut ad vel deserunt ullam. Molestiae maiores veritatis deserunt molestiae praesentium id laboriosam. Sit totam at et tempore nam accusamus non soluta. Quis debitis molestias sed et aliquam sint.",
"topic": {
"id": 6,
"created_at": "2020-03-29T16:50:40.000000Z",
"updated_at": "2020-03-29T16:50:40.000000Z",
"author_id": 11,
"forum_id": 14,
"deleted_at": null,
"name": "Repellendus suscipit commodi quia deleniti modi velit ut.",
"slug": "repellendus-suscipit-commodi-quia-deleniti-modi-velit-ut",
"content": null
},
"author": {
"id": 10,
"name": "Kaylah Lueilwitz",
"email": "[email protected]",
"email_verified_at": "2020-03-29T16:50:40.000000Z",
"created_at": "2020-03-29T16:50:40.000000Z",
"updated_at": "2020-03-29T16:50:40.000000Z"
}
}
},
nuxt index.vue:
<template>
<div>
<li v-for="forum in forums" :key="forum.id">
{{forum.name}}
<ul v-if="forum.last !== null">
<li v-for="last in forum.last">
{{last.topic.name}}
</li>
</ul>
</li>
</div>
</template>
如何显示诸如作者主题之类的关系?v-for表示其为空。
您好,我尝试使用laravel和nuxt制作应用程序,但无法显示模型中的关系。主要模型有:论坛论坛2.最后一个主题laravel的控制器:public ...
愚蠢解决
{{forum.last.author.name}}