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
How to display username instead of id in a list in octobercms
858 views Asked by H2O3 At
2
There are 2 answers
0
On
in your YourModel.php ,add this relation
public $hasOne = [
'user' => ['Backend\Models\User', 'key' => 'id', 'otherKey' => 'user_id']
];
in your columns.yaml,add this
user:
label: 'Username'
type: text
select: username //field from users table
relation: user //relation name is the key defined in model "hasone" relation
Hi you have to use the relation field type, change your
columns.yaml
and instead of useuser_id
something like this:And remember
user
is the name of your relationship defined in thebelongsTo
arrayYou should have defined the relationship right in your model
For further information http://octobercms.com/docs/backend/lists#column-relation