New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

gamez/typed-collection

Type-safe collections based on Laravel Collections
391,514 46

Larablocks Analysis

gamez/typed-collection works with Laravel 12 and 13 (latest release 8.1.2, Nov 17, 2026).

Laravel 8 to 11 in earlier releases.

Recommendation checks

Solid choice

Solid choice: maintained and up to date, meets 2 of 4 checks; below the bar for Recommended on use.

  • Works with Laravel 13, the current version
  • Released in the last 12 months (Nov 17, 2026)
  • 4,908 downloads a month (needs 10,000)
  • 46 GitHub stars (needs 100)

State

Actively maintained
  • Last stable release: Nov 17, 2026.
  • 3 releases in the last 12 months.
  • First released: Aug 31, 2017.
  • Monthly downloads: 4,908, down 47% from six months ago.
  • 1 open issue on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 28, 2026.

Install
composer require gamez/typed-collection
Latest Version:8.1.2
Laravel:12 · 13
Older releases:8 – 11
License:MIT
Last Updated:Nov 26, 2026
Links: GitHub  ·  Packagist
Maintainer: jeromegamez

Type-safe PHP collections based on Laravel Collections

Current version Total Downloads Tests Sponsor

[!NOTE]
Laravel 11 added the ensure() collection method that verifies that all elements of a collection are of a given type or list of types. However, this verification does not prevent items of different types to be added at a later time.

[!NOTE]
If you use Laravel collections combined with Larastan/PHPStan, you won't need this library and can just™ annotate your collection classes directly.

Installation

The package can be installed with Composer:

$ composer require gamez/typed-collection

Usage

class Person
{
    public $name;

    public function __construct($name)
    {
        $this->name = $name;
    }
}

$taylor = new Person('Taylor');
$jeffrey = new Person('Jeffrey');

Typed Collections

use Gamez\Illuminate\Support\TypedCollection;

/**
 * @extends TypedCollection<array-key, Person> 
 */
class People extends TypedCollection
{
    protected static array $allowedTypes = [Person::class];
}

$people = People::make([$taylor, $jeffrey])
    ->each(function (Person $person) {
        printf("This is %s.\n", $person->name);
    });
/* Output:
This is Taylor.
This is Jeffrey.
*/

try {
    People::make('Not a person');
} catch (InvalidArgumentException $e) {
    echo $e->getMessage().PHP_EOL;
}
/* Output:
A People collection only accepts items of the following type(s): Person.
*/

Lazy Typed Collections

use Gamez\Illuminate\Support\LazyTypedCollection;

/**
 * @extends LazyTypedCollection<array-key, Person> 
 */
class LazyPeople extends LazyTypedCollection
{
    protected static array $allowedTypes = [Person::class];
}

$lazyPeople = LazyPeople::make([$taylor, $jeffrey])
    ->each(function (Person $person) {
        printf("This is %s.\n", $person->name);
    });
/* Output:
This is Taylor.
This is Jeffrey.
*/

try {
    LazyPeople::make('Nope!');
} catch (InvalidArgumentException $e) {
    echo $e->getMessage().PHP_EOL;
}
/* Output:
A LazyPeople collection only accepts items of the following type(s): Person.
*/

Mixed collections

/**
 * @extends TypedCollection<array-key, int|string|Person>
 */
class MixedTypeCollection extends TypedCollection
{
    protected static array $allowedTypes = ['int', 'string', Person::class];
}

Supported types

Supported types are class strings, like Person::class, or types recognized by the get_debug_type() function, int, float, string, bool, and array.

Helper functions

The typedCollect() helper function enables you to dynamically create typed collections on the fly:

$dateTimes = typedCollect([new DateTime(), new DateTime()], DateTimeInterface::class);

For further information on how to use Laravel Collections, have a look at the official documentation.

Related Packages

webparking/laravel-type-safe-collection

This package provides type-safe extension of the laravel collection, forcing a s...

8,240 37
sa7bi/euro16

CLI Tool to keep you up to date with EURO-2016

4 0
pragmarx/coollection

Laravel Illuminate collection with objectified properties

3,608,902 94
softonic/laravel-collection-extended

Additional collection methods.

63,898 1
melihovv/collection-grouped-by-model

A collection grouped by model

1,515 9

Version History

Version Released PHP Laravel License
8.1.2 ^12.0 || ^13.0 MIT
8.1.1 ^12.0 || ^13.0 MIT
8.1.0 ^12.0 || ^13.0 MIT
8.0.0 ^11.0 || ^12.0 MIT
7.1.0 ^10.0 || ^11.0 MIT