Laravel 如何使用Inertia::render将特定模型的关系显示在表中?
我试图从控制器中获取模型的关系,以便能够显示关系,而不是作为id,而是作为该id的名称或类型或任何可能的内容。在本例中,我试图获取与一个问题相关的信息,该问题的回答类型(文本、多重、等级、是或否)以及属于哪个部分(名称) 这是到目前为止我的控制器代码Laravel 如何使用Inertia::render将特定模型的关系显示在表中?,laravel,vue.js,element-ui,inertiajs,Laravel,Vue.js,Element Ui,Inertiajs,我试图从控制器中获取模型的关系,以便能够显示关系,而不是作为id,而是作为该id的名称或类型或任何可能的内容。在本例中,我试图获取与一个问题相关的信息,该问题的回答类型(文本、多重、等级、是或否)以及属于哪个部分(名称) 这是到目前为止我的控制器代码 public function index() { return Inertia::render('Question/Index', [ 'survey_question' => SurveyQuestion::all
public function index()
{
return Inertia::render('Question/Index', [
'survey_question' => SurveyQuestion::all(),
'survey_section' => SurveySection::all(),
'response_type' => ResponseType::all()
]);
}
vue中的表
<el-table
:data="tableData">
<el-table-column
prop="question"
label="Pregunta">
</el-table-column>
<el-table-column
label="Seccion">
<template slot-scope="scope">
<p> {{ scope.row.survey_section.title }} </p>
</template>
</el-table-column>
<el-table-column
label="Tipo de Respuesta">
<template slot-scope="scope">
<p> {{ scope.row.response_type.type }} </p>
</template>
</el-table-column>
<el-table-column
prop="optional"
label="Opcional">
</el-table-column>
<el-table-column>
<template slot-scope="scope">
<div class="btn-link-edit action-button" @click="edit(scope.row)">
<i class="fas fa-pencil-alt"></i>
</div>
<div class="btn-link-delete action-button" @click="delete(scope.row)">
<i class="fas fa-trash"></i>
</div>
</template>
</el-table-column>
</el-table>
我想要的是,当我执行
{{scope.row}}
时,我还可以从这些id中获得另一个数组,其中包含与该id相关的信息,包括来自节和响应类型的信息。您如何转换数据并不明显,因此很难在这方面为您提供帮助。在这种情况下,范围
变量是什么?您是否在重复示例中的调查问题
道具?请包括相关文件的完整文件。
{ "id": 1, "question": "asdfasdf", "survey_section_id": 1, "response_type_id": 1, "optional": 1 }