php - Remove values with null from laravel api
one text
I have an api that fetches data of users who are admins of certain groups. But the api is returning all the users and displaying null on the groups. How can I get rid of the users with the null groups and query only the group admins? Thank you
Here is my Eloquent relationship
public function groupadmin()
{
return $this->hasOne(Group::class, 'admin_id', 'id');
}
And the Controller
public function users()
{
$user = User::with('groupadmin')->get();
return response()->json([
'status'=>200,
'user'=>$user,
]);
}
Please help. Thank you
Source