| Package Data | |
|---|---|
| Maintainer Username: | jeromegamez |
| Maintainer Contact: | jerome@gamez.name (Jérôme Gamez) |
| Package Create Date: | 2017-08-31 |
| Package Last Update: | 2025-08-12 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-11-11 03:01:22 |
| Package Statistics | |
|---|---|
| Total Downloads: | 260,357 |
| Monthly Downloads: | 11,492 |
| Daily Downloads: | 378 |
| Total Stars: | 45 |
| Total Watchers: | 2 |
| Total Forks: | 6 |
| Total Open Issues: | 1 |
The package can be installed with Composer:
$ composer require gamez/typed-collection
use Gamez\Illuminate\Support\TypedCollection;
class Person
{
public $name;
public function __construct($name)
{
$this->name = $name;
}
}
class People extends TypedCollection
{
protected static $allowedTypes = [Person::class];
}
People::make([new Person('Taylor'), new Person('Jeffrey')])
->each(function (Person $person) {
printf("This is %s.\n", $person->name);
});
/* Output:
This is Taylor.
This is Jeffrey.
*/
try {
People::make('Nope!');
} catch (InvalidArgumentException $e) {
echo $e->getMessage().PHP_EOL;
// Output: A People collection only accepts objects of the following types: Person.
}
For further information on how to use Laravel Collections, have a look at the official documentation.