PHP code example of soyhuce / empty-collection

1. Go to this page and download the library: Download soyhuce/empty-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/ */

    

soyhuce / empty-collection example snippets


empty_collection('int', 'int'); // Illuminate\Support\Collection<int, int>
empty_collection('int', 'string'); // Illuminate\Support\Collection<int, string>
empty_collection('string', 'array<string, bool>'); // Illuminate\Support\Collection<string, array<string, bool>>
empty_collection('string', Item::class); // Illuminate\Support\Collection<string, App\Service\Item>

empty_eloquent_collection('int', User::class); // Illuminate\Database\Eloquent\Collection<int, App\Models\User>
empty_eloquent_collection('string', User::class); // Illuminate\Database\Eloquent\Collection<string, App\Models\User>
diff
class MyService {

    /**
     * @var \Illuminate\Support\Collection<int, App\Service\Item>
     */
    private Collection $items;

    public function __construct()
    {
-        $this->items = collect();
+        $this->items = empty_collection('int', Item::class);
    }
}