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
Asked
Active
Viewed 845 times
2 Answers
1
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

OsDev
- 1,243
- 9
- 20
-
Thank you OsDev for the answer. It works for my case. – H2O3 Sep 18 '17 at 16:02
0
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

Tharanga
- 47
- 1
- 6