Skip to content

Commit

Permalink
Merge branch 'main' of github.com:postare/db-config
Browse files Browse the repository at this point in the history
  • Loading branch information
inerba committed Feb 28, 2024
2 parents 406f699 + cde721b commit c4b7516
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
7 changes: 2 additions & 5 deletions src/AbstractPageSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Support\Exceptions\Halt;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

abstract class AbstractPageSettings extends Page implements HasForms
{
Expand All @@ -30,8 +27,8 @@ public function mount(): void

public function save(): void
{
collect($this->form->getState())->each(function ($setting,$key) {
DbConfig::set($this->settingName().'.'.$key, $setting);
collect($this->form->getState())->each(function ($setting, $key) {
DbConfig::set($this->settingName() . '.' . $key, $setting);
});

Notification::make()
Expand Down
9 changes: 2 additions & 7 deletions src/Commands/DbConfigUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Pluralizer;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Postare\DbConfig\DbConfig;
Expand Down Expand Up @@ -39,7 +38,7 @@ public function handle(): void
$this->info('Updating database table');

// Check if table exists and has the field group
if (Schema::hasTable('db_config') && !Schema::hasColumn('db_config', 'group')) {
if (Schema::hasTable('db_config') && ! Schema::hasColumn('db_config', 'group')) {
$this->info('Adding field group to db_config table');
Schema::table('db_config', function ($table) {
$table->string('group')->after('id');
Expand All @@ -49,12 +48,11 @@ public function handle(): void
$this->info('table db_config already has field group');
}


$groups = DB::table('db_config')
->where('group', '')
->get();

if($groups->count() > 0) {
if ($groups->count() > 0) {
$this->info('Updating group field in db_config table');

foreach ($groups as $group) {
Expand All @@ -77,8 +75,5 @@ public function handle(): void
$this->info('No records to update');
}


}


}
12 changes: 5 additions & 7 deletions src/DbConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class DbConfig
/**
* Retrieve a configuration value from the database.
*
* @param string $key The configuration key.
* @param mixed $default The default value to return if the configuration key is not found.
* @param string $key The configuration key.
* @param mixed $default The default value to return if the configuration key is not found.
* @return mixed The configuration value.
*/
public static function get(string $key, mixed $default = null): mixed
Expand Down Expand Up @@ -40,9 +40,8 @@ public static function get(string $key, mixed $default = null): mixed
/**
* Set a configuration value in the database.
*
* @param string $key The configuration key.
* @param mixed $value The configuration value.
* @return void
* @param string $key The configuration key.
* @param mixed $value The configuration value.
*/
public static function set(string $key, mixed $value): void
{
Expand All @@ -68,7 +67,7 @@ public static function set(string $key, mixed $value): void
/**
* Retrieves the settings for a specific group from the database.
*
* @param string $group The group name.
* @param string $group The group name.
* @return array|null The settings for the group, or null if no settings are found.
*/
public static function getGroup(string $group): ?array
Expand All @@ -81,5 +80,4 @@ public static function getGroup(string $group): ?array

return $settings;
}

}

0 comments on commit c4b7516

Please sign in to comment.