diff --git a/routes/api.php b/routes/api.php index 3f0cb46..a26dd2a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,7 +1,6 @@ replace($lowerType, ''); } - if (!str($name)->endsWith($type)) { - $name = $name . $type; + if (! str($name)->endsWith($type)) { + $name = $name.$type; } return $name; @@ -62,7 +60,7 @@ protected function makeResource($name) ); if (file_exists($path)) { - if (!$this->option('force')) { + if (! $this->option('force')) { $this->error('Resource already exists!'); return; @@ -72,7 +70,7 @@ protected function makeResource($name) unlink($path); } - if (!file_exists($this->novaSettingsPath())) { + if (! file_exists($this->novaSettingsPath())) { mkdir($this->novaSettingsPath()); } @@ -80,12 +78,12 @@ protected function makeResource($name) $path, str_replace( ['{{namespace}}', '{{resource_name}}', '{{setting_name}}', '{{field_label}}', '{{field_attribute}}', '{{title_name}}', '{{order}}', '{{description}}'], - [$this->getNamespace(), $resource_name, $setting_name, $name . ' Field Label', str($name)->trim()->snake()->slug(), $resource_name, $countResource, Inspiring::quotes()->random(preserveKeys: true)], + [$this->getNamespace(), $resource_name, $setting_name, $name.' Field Label', str($name)->trim()->snake()->slug(), $resource_name, $countResource, Inspiring::quotes()->random(preserveKeys: true)], $this->getStub('SettingResource') ) ); $this->info('Resource created successfully.'); - $this->line('Resource path: ' . str($path)->replace(base_path(), '')->replaceFirst('/', '')); + $this->line('Resource path: '.str($path)->replace(base_path(), '')->replaceFirst('/', '')); } } diff --git a/src/Http/Controllers/SettingsController.php b/src/Http/Controllers/SettingsController.php index d581de8..87c6ace 100644 --- a/src/Http/Controllers/SettingsController.php +++ b/src/Http/Controllers/SettingsController.php @@ -5,9 +5,7 @@ use Ferdiunal\NovaSettings\Traits\Utils; use Illuminate\Http\JsonResponse; use Illuminate\Routing\Controller; -use Illuminate\Support\Facades\Context; use Illuminate\Support\Facades\Validator; -use Illuminate\Support\LazyCollection; use Laravel\Nova\Contracts\Resolvable; use Laravel\Nova\Http\Requests\NovaRequest; diff --git a/src/NovaSettings.php b/src/NovaSettings.php index 118b8f3..16cb66d 100644 --- a/src/NovaSettings.php +++ b/src/NovaSettings.php @@ -3,8 +3,6 @@ namespace Ferdiunal\NovaSettings; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Context; -use Illuminate\Support\LazyCollection; use Laravel\Nova\Menu\MenuItem; use Laravel\Nova\Menu\MenuSection; use Laravel\Nova\Nova; @@ -19,8 +17,8 @@ class NovaSettings extends Tool */ public function boot() { - Nova::script('nova-settings', __DIR__ . '/../dist/js/tool.js'); - Nova::style('nova-settings', __DIR__ . '/../dist/css/tool.css'); + Nova::script('nova-settings', __DIR__.'/../dist/js/tool.js'); + Nova::style('nova-settings', __DIR__.'/../dist/css/tool.css'); } /** diff --git a/src/NovaSettingsToolServiceProvider.php b/src/NovaSettingsToolServiceProvider.php index bb8be36..1efe398 100644 --- a/src/NovaSettingsToolServiceProvider.php +++ b/src/NovaSettingsToolServiceProvider.php @@ -4,10 +4,8 @@ use Ferdiunal\NovaSettings\Console\MakeSettingResource; use Ferdiunal\NovaSettings\Http\Middleware\Authorize; -use Ferdiunal\NovaSettings\Traits\Utils; use Illuminate\Log\Context\Repository as ContextRepository; use Illuminate\Support\Facades\Route; -use Illuminate\Support\LazyCollection; use Illuminate\Support\ServiceProvider; use Laravel\Nova\Events\ServingNova; use Laravel\Nova\Http\Middleware\Authenticate; @@ -22,12 +20,12 @@ class NovaSettingsToolServiceProvider extends ServiceProvider */ public function boot() { - if (!$this->app->configurationIsCached()) { - $this->mergeConfigFrom(__DIR__ . '/../config/nova-settings.php', 'nova-settings'); + if (! $this->app->configurationIsCached()) { + $this->mergeConfigFrom(__DIR__.'/../config/nova-settings.php', 'nova-settings'); } $this->publishes([ - __DIR__ . '/../config/nova-settings.php' => config_path('nova-settings.php'), + __DIR__.'/../config/nova-settings.php' => config_path('nova-settings.php'), ], 'nova-settings-config'); if ($this->app->runningInConsole()) { @@ -61,11 +59,11 @@ protected function routes() } Nova::router(['nova', Authenticate::class, Authorize::class], 'nova-settings') - ->group(__DIR__ . '/../routes/inertia.php'); + ->group(__DIR__.'/../routes/inertia.php'); Route::middleware(['nova', Authorize::class]) ->prefix('nova-vendor/nova-settings') - ->group(__DIR__ . '/../routes/api.php'); + ->group(__DIR__.'/../routes/api.php'); } /** @@ -73,7 +71,5 @@ protected function routes() * * @return void */ - public function register() - { - } + public function register() {} } diff --git a/src/Traits/Utils.php b/src/Traits/Utils.php index 050e788..14c1a21 100644 --- a/src/Traits/Utils.php +++ b/src/Traits/Utils.php @@ -17,7 +17,7 @@ protected function makeFakeResource(string $fieldName, $fieldValue) protected function getStub($name) { return file_get_contents( - realpath(__DIR__ . "/../../stubs/{$name}.stub") + realpath(__DIR__."/../../stubs/{$name}.stub") ); } diff --git a/src/helpers.php b/src/helpers.php index 5e5370b..99c00aa 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -7,37 +7,33 @@ use Illuminate\Support\Facades\File; use Illuminate\Support\LazyCollection; -if (!function_exists('settings')) { - function settings(?string $group = null) +if (! function_exists('settings')) { + function settings(?string $group = null, string|null|bool|array|object|int $default = null) { - return once( - function () use (&$group) { - $helper = new SettingsHelper( - group: $group - ); + $helper = new SettingsHelper( + group: $group + ); - if ($group) { - if (str($group)->contains('.')) { - [$_group, $_key] = str($group)->explode('.')->take(2); + if ($group) { + if (str($group)->contains('.')) { + [$_group, $_key] = str($group)->explode('.')->take(2); - return $helper->{$_group}->{$_key}; - } + return $helper->{$_group}->{$_key} ?? $default; + } - return $helper->{$group}; - } + return $helper->{$group} ?? $default; + } - return $helper; - } - ); + return $helper ?? $default; } } -if (!function_exists('getSettingReourceNamespace')) { +if (! function_exists('getSettingReourceNamespace')) { function getSettingReourceNamespace(): string { $path = preg_replace( [ - '/^(' . preg_quote(base_path(), '/') . ')/', + '/^('.preg_quote(base_path(), '/').')/', '/\//', ], [ @@ -58,13 +54,12 @@ function getSettingReourceNamespace(): string } } - -if (!function_exists('settingsResources')) { - function settingsResources(): LazyCollection | Collection +if (! function_exists('settingsResources')) { + function settingsResources(): LazyCollection|Collection { $resourcePath = Config::get('nova-settings.setting_resource_class_path', 'app/NovaSettings'); $namespace = getSettingReourceNamespace(); - if (!File::exists($resourcePath)) { + if (! File::exists($resourcePath)) { return new Collection([]); }