1. Go to this page and download the library: Download ashallendesign/type-safe library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
useApp\Models\User;
useAshAllenDesign\TypeSafe\Check;
useIlluminate\Support\Collection;
classLaravelUserCollectionimplementsCheck{
publicfunctionpasses(mixed $prop): bool{
if (!$prop instanceof Collection) {
returnfalse;
}
return $prop->whereInstanceOf(User::class)->count() === $prop->count();
}
publicfunctionmessage(mixed $prop): string{
return'One of the items is not a User model.';
}
}
$collection = collect([new User(), new TestCase()]);
safe($collection, new LaravelUserCollection());