Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdiunal committed Jul 11, 2024
1 parent 37c85e6 commit cc6da7a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 50 deletions.
1 change: 0 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use Ferdiunal\NovaSettings\Http\Controllers\SettingsController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
Expand Down
1 change: 0 additions & 1 deletion routes/inertia.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\LazyCollection;
use Laravel\Nova\Http\Requests\NovaRequest;

use function Ferdiunal\NovaSettings\settingsResources;
Expand Down
14 changes: 6 additions & 8 deletions src/Console/MakeSettingResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Ferdiunal\NovaSettings\Traits\Utils;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Context;
use Illuminate\Support\LazyCollection;

use function Ferdiunal\NovaSettings\settingsResources;

Expand Down Expand Up @@ -44,8 +42,8 @@ protected function getFilename(string $name, string $type): string
$name = str($name)->replace($lowerType, '');
}

if (!str($name)->endsWith($type)) {
$name = $name . $type;
if (! str($name)->endsWith($type)) {
$name = $name.$type;
}

return $name;
Expand All @@ -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;
Expand All @@ -72,20 +70,20 @@ protected function makeResource($name)
unlink($path);
}

if (!file_exists($this->novaSettingsPath())) {
if (! file_exists($this->novaSettingsPath())) {
mkdir($this->novaSettingsPath());
}

file_put_contents(
$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('/', ''));
}
}
2 changes: 0 additions & 2 deletions src/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 2 additions & 4 deletions src/NovaSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
}

/**
Expand Down
16 changes: 6 additions & 10 deletions src/NovaSettingsToolServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down Expand Up @@ -61,19 +59,17 @@ 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');
}

/**
* Register any application services.
*
* @return void
*/
public function register()
{
}
public function register() {}
}
2 changes: 1 addition & 1 deletion src/Traits/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}

Expand Down
41 changes: 18 additions & 23 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(), '/').')/',
'/\//',
],
[
Expand All @@ -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([]);
}

Expand Down

0 comments on commit cc6da7a

Please sign in to comment.