[英]How to display relationship data in Laravel Inertia Vue 3?
I'm new to laravel-inertia-vue3.我是 laravel-inertia-vue3 的新手。 I have following code in controller.
我在控制器中有以下代码。
$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 and DailyRevenue are two models and DailyRevenue belongs to tax. Tax和DailyRevenue是两个模型,DailyRevenue属于tax。 I have following code in DailyRevenue model.
我在 DailyRevenue 模型中有以下代码。
public function tax(){
return $this->belongsTo(Tax::class);
}
In index.vue file I have following code:在 index.vue 文件中,我有以下代码:
<Table :resource="revenue"/>
There is a column called tax_name in Tax model. Tax 模型中有一个名为 tax_name 的列。 I want to display tax_name in the table but unable to add column from controller.
我想在表中显示 tax_name 但无法从控制器添加列。 Is there any way to do this?
有什么办法吗? Thanks in advance.
提前致谢。
It was so simple.很简单。 I found following solution.
我找到了以下解决方案。 It worked perfectly.
它工作得很好。
<Table :resource="revenue">
<template #cell(tax_name)="{ item: tax }">
{{tax.tax.tax_name}}
</template>
</Table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.