Countries collection

4 years ago

aurawindsurfing

Code

$allCountries = collect([
  [
    'code' => 'DE',
    'name' => 'Germany',
    'phone' => null
  ],
  [
    'code' => 'US',
    'name' => 'United Stated',
    'phone' => '+1'
  ],
  [
    'code' => 'UK',
    'name' => 'United Kingdom',
    'phone' => '+44'
  ]
]);

$countries = $allCountries->whereNotNull('phone')->unique('phone');

Output

=> Illuminate\Support\Collection {#990
     all: [
       1 => [
         "code" => "US",
         "name" => "United Stated",
         "phone" => "+1",
       ],
       2 => [
         "code" => "UK",
         "name" => "United Kingdom",
         "phone" => "+44",
       ],
     ],
   }
HELO: Local email testing for your desktop!