diff --git a/src/HasTranslations.php b/src/HasTranslations.php index ed11e2a..05b1746 100644 --- a/src/HasTranslations.php +++ b/src/HasTranslations.php @@ -20,6 +20,7 @@ use LaravelLang\Models\Services\Registry; use LaravelLang\Models\Services\Relation; +use function app; use function filled; use function in_array; use function is_iterable; @@ -167,7 +168,7 @@ public function newInstance($attributes = [], $exists = false): static public function translatable(): array { - return Registry::get(__METHOD__, function () { + return app(Registry::class)->get(__METHOD__, function () { return (new (static::translationModelName())())->translatable(); }); } diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index fb5c5bc..729be33 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -7,9 +7,15 @@ use Illuminate\Support\ServiceProvider as BaseServiceProvider; use LaravelLang\Models\Console\ModelMakeCommand; use LaravelLang\Models\Console\ModelsHelperCommand; +use LaravelLang\Models\Services\Registry; class ServiceProvider extends BaseServiceProvider { + public function register(): void + { + $this->registry(); + } + public function boot(): void { if ($this->app->runningInConsole() || $this->app->runningUnitTests()) { @@ -32,4 +38,9 @@ protected function bootMigrations(): void __DIR__ . '/../database/migrations' ); } + + protected function registry(): void + { + $this->app->singleton(Registry::class, fn () => new Registry()); + } } diff --git a/src/Services/Registry.php b/src/Services/Registry.php index fc14b03..a4bede9 100644 --- a/src/Services/Registry.php +++ b/src/Services/Registry.php @@ -8,10 +8,10 @@ class Registry { - public static array $values = []; + protected array $values = []; - public static function get(string $key, Closure $callback): mixed + public function get(string $key, Closure $callback): mixed { - return static::$values[$key] ?? $callback(); + return $this->values[$key] ?? $callback(); } }