Skip to content

Commit 4c6fc9f

Browse files
- Fix CSS issue messing with inputs.\n - Handle settings defaults values.\n - Added support for laravel nova 5.
1 parent 9166e96 commit 4c6fc9f

File tree

8 files changed

+38
-94
lines changed

8 files changed

+38
-94
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"license": "MIT",
2323
"require": {
2424
"php": "^8.2",
25-
"spatie/laravel-settings": "^3.3",
26-
"laravel/nova": "^4.0"
25+
"spatie/laravel-settings": "^3.4",
26+
"laravel/nova": "^4.0|^5.0"
2727
},
2828
"autoload": {
2929
"psr-4": {

dist/css/tool.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/tool.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/css/tool.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* Nova Tool CSS */
22

3-
@tailwind base;
3+
/*@tailwind base;*/
44
@tailwind components;
55
@tailwind utilities;
66

7-
@layer base {
7+
@layer utilities {
88
.rounded-none {
99
border-radius: 0;
1010
}

resources/js/pages/Tool.vue

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,17 @@ export default {
290290
:is(.active\:text-white:is(.active *)) {
291291
color: white;
292292
}
293-
}
294293
295-
/* we will explain what these classes do next! */
296-
.v-enter-active,
297-
.v-leave-active {
298-
transition: opacity 0.3s ease;
299-
}
294+
/* we will explain what these classes do next! */
300295
301-
.v-enter-from,
302-
.v-leave-to {
303-
opacity: 0;
296+
.v-enter-active,
297+
.v-leave-active {
298+
transition: opacity 0.3s ease;
299+
}
300+
301+
.v-enter-from,
302+
.v-leave-to {
303+
opacity: 0;
304+
}
304305
}
305306
</style>

src/Contracts/SystemSettings.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
namespace Devloops\NovaSystemSettings\Contracts;
44

55
use Laravel\Nova\Makeable;
6-
use Spatie\LaravelSettings\SettingsMapper;
76
use Devloops\NovaSystemSettings\Components\Settings;
87
use Spatie\LaravelSettings\Settings as SpatieSettings;
9-
use Devloops\NovaSystemSettings\Traits\ManeuversSettingsMigration;
108

119
/**
1210
* Class SystemSettings.
@@ -18,7 +16,6 @@
1816
abstract class SystemSettings extends SpatieSettings
1917
{
2018
use Makeable;
21-
use ManeuversSettingsMigration;
2219

2320
/**
2421
* System setting's Settings component.
@@ -78,19 +75,4 @@ public function getSettingsComponent(): SettingsContract
7875
return $this->settings;
7976
}
8077

81-
/**
82-
* Migrate and set default values.
83-
*
84-
* @return void
85-
*/
86-
public function migrateDefaultValues(): void
87-
{
88-
foreach (
89-
$this->getSettingsComponent()
90-
->getFieldsKeys() as $fieldKey
91-
) {
92-
$this->getRepository()
93-
->createProperty($this->getGroup(), $fieldKey, null);
94-
}
95-
}
9678
}

src/SettingsMapper.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
/**
1212
* Class SettingsMapper.
1313
*
14+
* @see https://github.com/spatie/laravel-settings/pull/298 Taken from this PR to fix default values setting.
15+
* @author Abdullah Al-Faqeir <abdullah@devloops.net>
1416
* @package Devloops\NovaSystemSettings
1517
* @date 09/05/2024
16-
* @author Abdullah Al-Faqeir <abdullah@devloops.net>
1718
*/
1819
class SettingsMapper extends SpatieSettingsMapper
1920
{
@@ -45,6 +46,7 @@ public function load(string $settingsClass): Collection
4546

4647
event(new LoadingSettings($settingsClass, $properties));
4748

49+
$properties = $this->fillMissingSettingsWithDefaultValues($config, $properties);
4850
$this->ensureNoMissingSettings($config, $properties, 'loading');
4951

5052
return $properties;
@@ -109,6 +111,25 @@ private function getConfig(string $settingsClass): SettingsConfig
109111
return $this->configs[$settingsClass];
110112
}
111113

114+
private function fillMissingSettingsWithDefaultValues(SettingsConfig $config, Collection $properties): Collection
115+
{
116+
$config->getReflectedProperties()
117+
->keys()
118+
->diff($properties->keys())
119+
->each(function ($missingSetting) use ($config, &$properties) {
120+
/** @var ReflectionProperty $reflectionProperty */
121+
$reflectionProperty = $config->getReflectedProperties()[$missingSetting];
122+
123+
if ($reflectionProperty->hasDefaultValue()
124+
|| $reflectionProperty->getType()
125+
->allowsNull()) {
126+
$properties->put($missingSetting, $reflectionProperty->getDefaultValue());
127+
}
128+
});
129+
130+
return $properties;
131+
}
132+
112133
private function ensureNoMissingSettings(
113134
SettingsConfig $config,
114135
Collection $properties,

src/Traits/ManeuversSettingsMigration.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)