diff --git a/src/LostInTranslationServiceProvider.php b/src/LostInTranslationServiceProvider.php index 34a2ab7..ebba48e 100644 --- a/src/LostInTranslationServiceProvider.php +++ b/src/LostInTranslationServiceProvider.php @@ -4,6 +4,8 @@ use CodingSocks\LostInTranslation\Console\Commands\FindMissingTranslationStrings; use Illuminate\Contracts\Filesystem\Filesystem; +use Illuminate\Support\Arr; +use Illuminate\Support\Collection; use Illuminate\Support\ServiceProvider; class LostInTranslationServiceProvider extends ServiceProvider @@ -42,6 +44,12 @@ public function register() $this->app->singleton('lost-in-translation', function ($app) { return $app->make(LostInTranslation::class); }); + + if (! method_exists(Collection::class, 'dot') && ! Collection::hasMacro('dot')) { + Collection::macro('dot', function () { + return new Collection(Arr::dot($this->all())); + }); + } } /** diff --git a/tests/LostInTranslationServiceProviderTest.php b/tests/LostInTranslationServiceProviderTest.php index 490804e..8bdb0c3 100644 --- a/tests/LostInTranslationServiceProviderTest.php +++ b/tests/LostInTranslationServiceProviderTest.php @@ -3,6 +3,7 @@ namespace CodingSocks\LostInTranslation\Tests; use CodingSocks\LostInTranslation\LostInTranslation; +use Illuminate\Support\Collection; class LostInTranslationServiceProviderTest extends TestCase { @@ -42,4 +43,15 @@ public function testDefaultConfig() ], ], $config['detect']); } + + public function testCollectionMacro() + { + $value = Collection::make([ + 'foo' => [ + 'bar' => 'baz' + ], + ])->dot()->all(); + + $this->assertEquals(['foo.bar' => 'baz'], $value); + } } \ No newline at end of file