© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
1 reply
Hung Thai

Display Table info with Recursive Relationship

Hi. I'm having hard-time trying to display nested relationship in the table.
For example, these 2 Models:
Category:

public function products() {
    return $this->hasMany(Product::class);
}

public function products() {
    return $this->hasMany(Product::class);
}


and
Product:

public function category() {
    if ($this->parent) {
            //recursive to get the root category
            return $this->parent->category(); 
        }
    return $this->belongsTo(Category::class);
}

public function parent() {
    return $this->belongsTo(Product::class);
}

public function category() {
    if ($this->parent) {
            //recursive to get the root category
            return $this->parent->category(); 
        }
    return $this->belongsTo(Category::class);
}

public function parent() {
    return $this->belongsTo(Product::class);
}

And then I had:
- Category id = 1 which had Product id = 1 as it's child.
- Product id = 1 which had Product id = 2 as it's child.

I can play around in tinker and extract the category from Product id 2 like:
\App\Models\Product::find(2)->category
\App\Models\Product::find(2)->category

, but somehow on the table, the relationship category of Product id 2 return null. My column like:
Tables\Columns\TextColumn::make('category.name')
Tables\Columns\TextColumn::make('category.name')

Product 1 show the category just fine, Product 2 just returned null.

How can I fix this? Thank you.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Filter with recursive relationship
FilamentFFilament / ❓┊help
3y ago
Display relationship on table column
FilamentFFilament / ❓┊help
3y ago
recursive table
FilamentFFilament / ❓┊help
2y ago
relationship not display
FilamentFFilament / ❓┊help
2y ago