Ad

How To Display Username Instead Of Id In A List In Octobercms

- 1 answer

In my case I have a backend list and I got the updated UserId on the list. But I have no Idea how to display the Username instead of the UserId. Is there anyone can help me to get out of this? See the list here

Ad

Answer

Hi you have to use the relation field type, change your columns.yaml and instead of use user_id something like this:

user:
 label: Username
 type: relation
 select: login

And remember user is the name of your relationship defined in the belongsTo array

You should have defined the relationship right in your model

<?php

class YourModel extends Model
{
  $belongsTo = ['user'=>'Backend\Models\User'];
}

For further information http://octobercms.com/docs/backend/lists#column-relation

Ad
source: stackoverflow.com
Ad