Access Relationship Data in Table Layout Custom HTML

How to access relationship data in Table Layout: Custom HTML. I have products and I want to show their variants in the custom HTML. https://filamentphp.com/docs/3.x/tables/layout#custom-html
<?php
//Product Model
public function variants(): HasMany
{
return $this->hasMany(ProductVariant::class);
}
<?php
//Product Model
public function variants(): HasMany
{
return $this->hasMany(ProductVariant::class);
}
```<?php
// ProductResource.php
View::make('products.table.collapsible-row-content')
->collapsible(),
```<?php
// ProductResource.php
View::make('products.table.collapsible-row-content')
->collapsible(),
<?php
// I try below code in the blade file.
// resources/views/products/table/collapsible-row-content.blade.php
<p class="px-4 py-3 bg-gray-100 rounded-lg">
<span class="font-medium">
@foreach($getRecord()->variants() as $productVariant)
<p>{{$productVariant->description}}</p>
@endforeach
</span>
</p>
<?php
// I try below code in the blade file.
// resources/views/products/table/collapsible-row-content.blade.php
<p class="px-4 py-3 bg-gray-100 rounded-lg">
<span class="font-medium">
@foreach($getRecord()->variants() as $productVariant)
<p>{{$productVariant->description}}</p>
@endforeach
</span>
</p>
1 Reply
Sourabh
SourabhOP7mo ago
Please ignore it. i have found the solution // ListProducts page
<?php
protected function getTableQuery(): ?Builder
{
return parent::getTableQuery()->with(['variants']);
}
<?php
protected function getTableQuery(): ?Builder
{
return parent::getTableQuery()->with(['variants']);
}
Want results from more Discord servers?
Add your server