filamentphp / filamentphp/filament
[Table] - There is no way to access individual "-many" relationship models in column
- Dominant language
- PHP
- Stars
- 32.1k
- Forks
- 4.2k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 61
Description
### Package
filament/tables
### Package Version
v4, v5
### Laravel Version
v11, v12
### Livewire Version
v3, v4
### PHP Version
PHP 8.3+
### Problem description
Currently, there is a number of columns that support displaying a list of 1-n and n-n relationship: `TextColumn::make('tags.name')`, `ImageColumn::make('colleagues.avatar')->circular()->stacked()`, however, there is no "official" way to access other fields or the model itself.
Consider:
```
// suppose we have a TagModel with columns (name, color)
TextColumn::make('tags.name')
->badge()
->color( // 'tags.color') //here, $record will be the main table $record, $state will be `tag.name`, $rowLoop will be the row loop of the row itself, not the loop of tags
```
or
```
ImageColumn::make('colleagues.avatar')
->circular()
->stacked()
->tooltip(// 'colleagues.name')
```
Currently, some cases there are workaround, for example:
```
TextColumn::make('tags.name')
->badge()
->color(function ($record, $state){
$tag = $record->tags->firstWhere('name', $state);
return Color::hex($tag->color);
})
```
but at the end of the day, it is still a workaround, it wouldnt work if there is a record with `null` name, or duplicate name (it doesnt make sense with tag name, but other models may)
Speaking of which, there is currently no workaround for the avatar example, since $user->avatar may be null, or 2 user can use the same img url.
### Expected behavior
There should be a way to access the model itself, either directly, or through a $rowLoop-type variable.
```
function($relationshipRecord) {
}
```
or
```
function($model, $relationshipRowLoop) {
$model->relationship[$relationshipRowLoop->index]
}
```
### Steps to reproduce
1. Make a new filament project
2. Make a table
3. Make a HasMany or BelongsToMany relation
4. Try to access and customize individual relation model
### Reproduction repository (issue will be closed if this is not valid)
https://github.com/filamentphp/demo
### Relevant log output
```shell
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the relationship-aware behavior of TextColumn::make('tags.name') and ImageColumn::make('colleagues.avatar'), then reproduce the examples in the linked Filament demo repository. Define how callbacks can identify each related model even when values are null or duplicated, and verify that individual relationship customization works for HasMany and BelongsToMany columns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100