[英]How to display relationship data in Laravel Inertia Vue 3?
我是 laravel-inertia-vue3 的新手。 我在控制器中有以下代码。
$revenue = QueryBuilder::for(DailyRevenue::class)->with('tax')->paginate(50);
return Inertia::render('DailyRevenue/Index', ['revenue' => $revenue])->table(function (InertiaTable $table) {
$table->column('id', 'id', searchable: true, sortable: true);
$table->column('date', 'date', searchable: true, sortable: true);
$table->column('tax', "tax");
$table->column('amount', 'amount', sortable: true);
Tax和DailyRevenue是两个模型,DailyRevenue属于tax。 我在 DailyRevenue 模型中有以下代码。
public function tax(){
return $this->belongsTo(Tax::class);
}
在 index.vue 文件中,我有以下代码:
<Table :resource="revenue"/>
Tax 模型中有一个名为 tax_name 的列。 我想在表中显示 tax_name 但无法从控制器添加列。 有什么办法吗? 提前致谢。
很简单。 我找到了以下解决方案。 它工作得很好。
<Table :resource="revenue">
<template #cell(tax_name)="{ item: tax }">
{{tax.tax.tax_name}}
</template>
</Table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.