F
Filament11mo ago
slamx_

How to load specific model data into Table Builder?

I have a Model UserTracking that has the column user_id and here a one to one relationship exists. In the Table Builder I would now like to display the user name instead of the ID and if possible also load a model function as value. Is this possible? I didn't found a solution in the docs
4 Replies
eazy
eazy11mo ago
TextColumn::make('user.name')
TextColumn::make('user.name')
Or whatever your relation is called and the name is called on the model Also if the function is a attribute you can call it the same way with the attribute name
slamx_
slamx_11mo ago
@eazyurk thanks, but when I try to call a model function, I get the following error: App\Models\User::getUserDisplayName must return a relationship instance any Idea to fix this?
eazy
eazy11mo ago
yeah On the User model add a custom accessor for the display name like in the docs: https://laravel.com/docs/10.x/eloquent-mutators#defining-an-accessor propably something like this:
protected function displayName(): Attribute
{
return Attribute::make(
get: fn () => "$this->name $this->last_name",
);
}
protected function displayName(): Attribute
{
return Attribute::make(
get: fn () => "$this->name $this->last_name",
);
}
(or something like that) Then in your textcolumn you can do this:
TextColumn::make('user.display_name')
TextColumn::make('user.display_name')
slamx_
slamx_11mo ago
Many thanks!
Want results from more Discord servers?
Add your server
More Posts
Customizing the creation process of relationshipI found in docs that I can customize the creation process of resources. How to get relationship dataRefresh The Table in afterStateUpdated()Hello there, is possible afterStateUpdated update the table? for the case, im using the sushi calebcan we disable filter icon in table and add button instead of filter form to filtercan we disable filter icon in table and add button instead of filter form to filterDisable tenant ownership relationIn a Jetstream based app we're using the Teams setup. In our app however, not all models are strictlStore the full file upload URL not just the filesystem extensionI am trying to use the file upload field to store an image url to a model `image` column. I want theHow to rename / translate the title "SUMMARY" when using TOTAL SUM or AVERAGE of COLUMNHello. I am using the: ``` ->summarize([ Average::make()->label('Promedio')->foactiveLocale error in ListResource using Filament Spatie TranslatableI'm trying to set a translatable resource in a new v3 Filament install. I've added the Actions\LocalHaving a page with form and action button to saveHello Guys, I'm trying to made a page, with a form inside, for now a simple form, But it doesn'Can you hide the default menu but still discover the resources?I have my own `navigationItems` array - and I only want to see those items in the navigation. In FilRefresh table after changing values with updateStateUsingHello, I using CheckBoxColumn to select default language. I changing values of rows in updateStateUs