Skip to content

Instantly share code, notes, and snippets.

@kphrx
Last active June 18, 2018 17:21
Show Gist options
  • Save kphrx/72d873b8d5268a3432d323002f17256f to your computer and use it in GitHub Desktop.
Save kphrx/72d873b8d5268a3432d323002f17256f to your computer and use it in GitHub Desktop.
Add `isAssoc` to Collection class
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Collection;
use Illuminate\Support\Arr;
class IsAssocForCollectionServiceProvider extends ServiceProvider
{
public function boot()
{
// Result Arr::isAssoc
Collection::macro('isAssoc', function() {
if (!is_array($this->all())) {
return false;
}
return Arr::isAssoc($this->all());
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment