Users table #5512
-
While i am storing the users in database the roles and last login columns NOT show any data, how to handle this please |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Any answer ? |
Beta Was this translation helpful? Give feedback.
-
Any one to answer please ? |
Beta Was this translation helpful? Give feedback.
-
Might be a bug, create an issue? |
Beta Was this translation helpful? Give feedback.
-
Here's how I got it to show: app/Models/User.php // ...
use DB;
use Statamic\Auth\Role;
use Statamic\Auth\UserGroup;
// ...
public function getRolesAttribute()
{
$roles = DB::table('role_user')
->where('user_id', $this->id)
->get()
->transform(function ($roleUser) {
return $roleUser->role_id;
});
$groupRoles = $this->statamic_groups->reduce(function ($roles, $group) {
return $roles->concat($group->roles()->keys());
}, collect());
return $roles->concat($groupRoles)->unique();
}
public function getStatamicRolesAttribute()
{
return $this->roles->transform(function ($roleId) {
return Role::find($roleId);
});
}
public function getGroupsAttribute()
{
return DB::table('group_user')
->where('user_id', $this->id)
->get()
->transform(function ($groupUser) {
return $groupUser->group_id;
return UserGroup::find($groupUser->group_id);
});
}
public function getStatamicGroupsAttribute()
{
return $this->groups->transform(function ($groupId) {
return UserGroup::find($groupId);
});
}
// ... |
Beta Was this translation helpful? Give feedback.
Here's how I got it to show:
app/Models/User.php