过滤集合会更改其类型(如何按自定义属性过滤)

I have a collection of users that I want to filter by a custom attribute (accessor).

To the best of my knowledge one thing I could do id:

$filtered = Users::someScope()
    ->anotherScope()
    ->whereHas(function() { 'whatever' })
    ->get()
    ->where('custom_attribute', 5);

The other thing I could do to filter the collection separately after ->get():

$filtered = $users->filter(function($value, $key){
    return $value['custom_attribute'] == 5;
});

Then the variable is sent to Vuetify's dropdown to iterate.

Both produce the same result. I think they change the type of the variable.

Results:

If I return $filtered it shows [Object object] when iterating.

If I return $filtered->all() it throws an Htmlspecialchars expects string - array given

If I return before/without filtering - everything works okay.