Last active
June 18, 2018 17:21
-
-
Save kphrx/72d873b8d5268a3432d323002f17256f to your computer and use it in GitHub Desktop.
Add `isAssoc` to Collection class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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