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
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
@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?
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:
(or something like that)
Then in your textcolumn you can do this:
Many thanks!