Closed mjlandicho closed 4 years ago
You should be able to access the Role model like any other to get the data you need. It has a users()
relationship which you can use to count the number of users on each model. E.g. Role::first()->users()->count()
Please let me know if you need any more info. Cheers.
public function calculate(Request $request)
{
$result = Role::withCount([
'users' => static function (Builder $query) {
$query->whereNull('banned_at');
},
])
->orderBy('users_count', 'desc')
->get()
->mapWithKeys(static function ($item) {
return [$item['name'] => $item['users_count']];
})
->put('Banned', User::whereNotNull('banned_at')->count())
->toArray();
return $this->result($result);
}
how can i count data from Role model into my metric? I mean, I want to show in metric if how many admins, users. in my database users