|
@@ -0,0 +1,39 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace App\Providers\Macros;
|
|
|
|
+
|
|
|
|
+use Illuminate\Support\Arr;
|
|
|
|
+use Illuminate\Support\ServiceProvider;
|
|
|
|
+
|
|
|
|
+class ArrayProvider extends ServiceProvider
|
|
|
|
+{
|
|
|
|
+ /**
|
|
|
|
+ * Register services.
|
|
|
|
+ */
|
|
|
|
+ public function register(): void
|
|
|
|
+ {
|
|
|
|
+ //
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Bootstrap services.
|
|
|
|
+ */
|
|
|
|
+ public function boot(): void
|
|
|
|
+ {
|
|
|
|
+ // Some array macros
|
|
|
|
+ // Searching for key in nested array
|
|
|
|
+ Arr::macro('hasNestedKey', function ($key, $array) {
|
|
|
|
+ if (array_key_exists($key, $array)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($array as $element) {
|
|
|
|
+ if (is_array($element)) {
|
|
|
|
+ return Arr::hasNestedKey($key, $element);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+}
|