Laravel - Collections - Method Whereinstanceof

The whereInstanceOf method filters the collection by a given class type:

    
    use App\Models\User;
    use App\Models\Post;
    
    $collection = collect([
        new User,
        new User,
        new Post,
    ]);
    
    $filtered = $collection->whereInstanceOf(User::class);
    
    $filtered->all();
    
    // [App\Models\User, App\Models\User]