PHP code example of webparking / laravel-type-safe-collection

1. Go to this page and download the library: Download webparking/laravel-type-safe-collection library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webparking / laravel-type-safe-collection example snippets


/**
 * @method \ArrayIterator|User[] getIterator()
 * @method User|null             first()
 */
class UserCollection extends TypeSafeCollection
{
    protected $type = User::class;
}

class User extends Model
{
    public function newCollection(array $models = []): UserCollection
    {
        return new UserCollection($models);
    }
}

get_class(User::all()) // UserCollection
get_class(User::where('type', '=', 'admin')->get()) // UserCollection
get_class(User::where('id', '=', 1)->first()) // User