From eca616ac56786deb6bd06d269c1c78d8ea06781a Mon Sep 17 00:00:00 2001 From: Binyamin Blatt Date: Tue, 9 Apr 2024 17:06:39 +0300 Subject: [PATCH 1/8] ## [5.1.1-EPF] -2024-04-09 - ### Braking Change: Made the Models and Traits Publishable, so you can add SoftDeletes, auditing, and/or caching if you want (YOU MUST RUN THE INSTALLATION COMMAND) - ### Braking Change: Check your Namespaces - Moved the config functions to a Trait so adding functions is as simple as editing the published Trait or adding another Trait - I left the original `LaravelConfig` class as an alies of the Model, but it needs more testing - ### Braking Change: The Update function needed to be renamed from `update` to `update_config` - ### Braking Change: The Update function Only takes one parameter just the `ConfigItem` - ### Braking Change: The `update_config` helper Only takes one parameter just the `ConfigItem` - ### Braking Change: The Delete function needed to be renamed from `delete` to `delete_config` - Because of the Braking Changes I also added a `get_config`, `set_config`, `has_config`, and `create_config` aliases for consistency - NON Braking Change: Removed the `all` function as it's not needed anymore since it's a function of a Model - I'm adding more functions to another Trait that can be added by including it in the Model these are all traits that I've found useful --- CHANGELOG.md | 14 ++ README.md | 36 +-- config/config.php | 3 - database/factories/ConfigFactory.php | 6 +- src/Casts/ConfigValueCast.php | 23 +- src/Config/ConfigFactory.php | 9 +- src/Console/InstallCommand.php | 46 ++++ src/LaravelConfig.php | 83 ++----- src/LaravelConfigServiceProvider.php | 17 +- src/{Config => Models}/Config.php | 5 +- src/Traits/LaravelConfigDataByIdTrait.php | 94 +++++++ src/Traits/LaravelConfigTrait.php | 214 ++++++++++++++++ src/helpers.php | 25 +- tests/LaravelConfigOldTest.php | 289 ++++++++++++++++++++++ tests/LaravelConfigTest.php | 44 ++-- tests/TestCase.php | 18 +- 16 files changed, 788 insertions(+), 138 deletions(-) create mode 100644 src/Console/InstallCommand.php mode change 100755 => 100644 src/LaravelConfig.php rename src/{Config => Models}/Config.php (86%) create mode 100644 src/Traits/LaravelConfigDataByIdTrait.php create mode 100755 src/Traits/LaravelConfigTrait.php create mode 100644 tests/LaravelConfigOldTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 19f6459..7cf4984 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,20 @@ All notable changes to `laravel-config` will be documented in this file. ## [Unreleased] +## [5.1.1-EPF] -2024-04-09 + +- ### Braking Change: Made the Models and Traits Publishable, so you can add SoftDeletes, auditing, and/or caching if you want (YOU MUST RUN THE INSTALLATION COMMAND) +- ### Braking Change: Check your Namespaces +- Moved the config functions to a Trait so adding functions is as simple as editing the published Trait or adding another Trait +- I left the original `LaravelConfig` class as an alies of the Model, but it needs more testing +- ### Braking Change: The Update function needed to be renamed from `update` to `update_config` +- ### Braking Change: The Update function Only takes one parameter just the `ConfigItem` +- ### Braking Change: The `update_config` helper Only takes one parameter just the `ConfigItem` +- ### Braking Change: The Delete function needed to be renamed from `delete` to `delete_config` +- Because of the Braking Changes I also added a `get_config`, `set_config`, `has_config`, and `create_config` aliases for consistency +- NON Braking Change: Removed the `all` function as it's not needed anymore since it's a function of a Model +- I'm adding more functions to another Trait that can be added by including it in the Model these are all traits that I've found useful + ## [5.1.0] - 2024-04-08 - Laravel 11 and PHP 8.3 support added. diff --git a/README.md b/README.md index c689166..22012dc 100755 --- a/README.md +++ b/README.md @@ -16,21 +16,27 @@ You can install the package via composer: ```bash composer require tarfin-labs/laravel-config ``` -Next, you should publish the Laravel config migration file using the vendor:publish Artisan command. +Next, you MUST publish Models, Factories, and Traits +When updating you might need to rerun the installation command be warned this will overwrite any changes made to any of the published Models, Factories, and Traits +```bash +php artisan laravel-config:install ``` +Next, you should publish the Laravel config migration file using the vendor:publish Artisan command. + +```bash php artisan vendor:publish --provider="TarfinLabs\LaravelConfig\LaravelConfigServiceProvider" --tag="laravel-config" ``` If you want to use Laravel Config database factory, you can publish it too, using the command: -``` +```bash php artisan vendor:publish --provider="TarfinLabs\LaravelConfig\LaravelConfigServiceProvider" --tag="laravel-config-factories" ``` Finally, you should run your database migrations: -``` +```bash php artisan migrate ``` @@ -40,7 +46,7 @@ Simple usage example of laravel-config package in your Laravel app. Create new config parameter: -``` php +```php $factory = new ConfigFactory(); $configItem = $factory->setName('key') ->setType(ConfigDataType::BOOLEAN) @@ -54,37 +60,37 @@ LaravelConfig::create($configItem); Get value with config name: -``` php +```php LaravelConfig::get('key'); ``` Set value with config name and value: -``` php +```php LaravelConfig::set('key', 'value'); ``` Get all config parameters: -``` php +```php LaravelConfig::all(); ``` Get config items by tag: -``` php +```php LaravelConfig::getByTag('key'); ``` Check if the config exists: -``` php +```php LaravelConfig::has('key'); ``` Update config with new values: -``` php +```php $factory = new ConfigFactory($configId); $configItem = $factory->setName('updated-key') ->setType(ConfigDataType::BOOLEAN) @@ -93,13 +99,13 @@ $configItem = $factory->setName('updated-key') ->setDescription('updated description') ->get(); -LaravelConfig::update($configItem); +LaravelConfig::update_config($configItem); ``` Remove config: -``` php -LaravelConfig::delete('key'); +```php +LaravelConfig::delete_config('key'); ``` ### Nested Parameters @@ -141,7 +147,7 @@ LaravelConfig::getNested('foo'); ### Helpers You can also use helper functions: -``` php +```php // Creating config item $factory = new ConfigFactory(); $configItem = $factory->setName('key') @@ -182,7 +188,7 @@ read_nested('foo.bar'); ### Testing -``` bash +```bash composer test ``` diff --git a/config/config.php b/config/config.php index 3a388ca..cd8a3dc 100755 --- a/config/config.php +++ b/config/config.php @@ -1,8 +1,5 @@ env('LARAVEL_CONFIG_TABLE', 'laravel_config'), ]; diff --git a/database/factories/ConfigFactory.php b/database/factories/ConfigFactory.php index f47bbe8..9c22c87 100644 --- a/database/factories/ConfigFactory.php +++ b/database/factories/ConfigFactory.php @@ -1,13 +1,13 @@ define(Config::class, function (Faker $faker, array $attributes = []) { +$factory->define(ConfigModel::class, function (Faker $faker, array $attributes = []) { return [ 'name' => $attributes['name'] ?? $faker->word().$faker->asciify('*****'), 'type' => $attributes['type'] ?? $faker->randomElement(['boolean', 'text']), diff --git a/src/Casts/ConfigValueCast.php b/src/Casts/ConfigValueCast.php index c446cb2..c0d3c68 100644 --- a/src/Casts/ConfigValueCast.php +++ b/src/Casts/ConfigValueCast.php @@ -4,12 +4,20 @@ use Carbon\Carbon; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; -use Illuminate\Database\Eloquent\Model; use TarfinLabs\LaravelConfig\Enums\ConfigDataType; class ConfigValueCast implements CastsAttributes { - public function get(Model $model, string $key, mixed $value, array $attributes) + /** + * Transform the attribute from the underlying model values. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @param mixed $value + * @param array $attributes + * @return TGet|null + */ + public function get($model, string $key, mixed $value, array $attributes) { return match ($attributes['type']) { ConfigDataType::BOOLEAN->value => (bool) $value, @@ -21,7 +29,16 @@ public function get(Model $model, string $key, mixed $value, array $attributes) }; } - public function set(Model $model, string $key, mixed $value, array $attributes) + /** + * Transform the attribute to its underlying model values. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @param string $key + * @param TSet|null $value + * @param array $attributes + * @return mixed + */ + public function set($model, string $key, mixed $value, array $attributes) { return $value; } diff --git a/src/Config/ConfigFactory.php b/src/Config/ConfigFactory.php index 77cc1cf..25b02cf 100644 --- a/src/Config/ConfigFactory.php +++ b/src/Config/ConfigFactory.php @@ -2,19 +2,22 @@ namespace TarfinLabs\LaravelConfig\Config; +use App\Models\Config as ConfigModel; +use TarfinLabs\LaravelConfig\Config\ConfigItem; + class ConfigFactory { /** * @var ConfigItem */ - protected $configItem; + protected ConfigItem $configItem; /** * ConfigFactory constructor. * - * @param Config|null $config + * @param ConfigModel|null $config */ - public function __construct(Config $config = null) + public function __construct(ConfigModel $config = null) { $this->configItem = new ConfigItem(); diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php new file mode 100644 index 0000000..c9c32bc --- /dev/null +++ b/src/Console/InstallCommand.php @@ -0,0 +1,46 @@ +ensureDirectoryExists(app_path('Models/')); + (new Filesystem)->copyDirectory(__DIR__.'/../Models', app_path('Models/')); + + // Traits... + (new Filesystem)->ensureDirectoryExists(app_path('Traits/')); + (new Filesystem)->copyDirectory(__DIR__.'/../Traits', app_path('Traits/')); + + // Factory... + (new Filesystem)->ensureDirectoryExists(database_path('factories/')); + (new Filesystem)->copy(__DIR__.'/../../database/factories/ConfigFactory.php', database_path('factories/ConfigFactory.php')); + + $this->info('Laravel-config installed successfully.'); + } + +} diff --git a/src/LaravelConfig.php b/src/LaravelConfig.php old mode 100755 new mode 100644 index 8cd9b7b..24ba167 --- a/src/LaravelConfig.php +++ b/src/LaravelConfig.php @@ -3,7 +3,7 @@ namespace TarfinLabs\LaravelConfig; use Illuminate\Support\Collection; -use TarfinLabs\LaravelConfig\Config\Config; +use TarfinLabs\LaravelConfig\LaravelConfigFacade as ConfigFacade; use TarfinLabs\LaravelConfig\Config\ConfigItem; class LaravelConfig @@ -15,15 +15,13 @@ class LaravelConfig * @param $default * @return mixed */ - public function get(string $name, $default = null) + public function get(string $name, $default = null): mixed { - if (! $this->has($name)) { + if (!$this->has($name)) { return $default; } - $config = Config::where('name', $name)->first(); - - return $config->val; + return ConfigFacade::get($name); } /** @@ -34,37 +32,20 @@ public function get(string $name, $default = null) */ public function getNested(string $namespace): Collection { - $params = Config::where('name', 'LIKE', "{$namespace}.%")->get(); - - $config = collect(); - - foreach ($params as $param) { - $keys = explode('.', str_replace("{$namespace}.", '', $param->name)); - $name = ''; - - foreach ($keys as $key) { - $name .= $key.'.'; - } - - $param->name = rtrim($name, '.'); - - $config->push($param); - } - - return $config; + return ConfigFacade::getNested($namespace); } /** * @param $tags * @return Collection */ - public function getByTag($tags): ?Collection + public function getByTag($tags): Collection|null { if (! is_array($tags)) { $tags = [$tags]; } - return Config::whereJsonContains('tags', $tags)->get(); + return ConfigFacade::getByTag($tags); } /** @@ -74,18 +55,13 @@ public function getByTag($tags): ?Collection * @param $value * @return mixed */ - public function set(string $name, $value) + public function set(string $name, $value): mixed { if (! $this->has($name)) { - return; + return null; } - $config = Config::where('name', $name)->first(); - - $config->val = $value; - $config->save(); - - return $value; + return ConfigFacade::set($name, $value); } /** @@ -96,7 +72,7 @@ public function set(string $name, $value) */ public function has(string $name): bool { - return Config::where('name', $name)->count() > 0; + return ConfigFacade::has($name); } /** @@ -104,9 +80,9 @@ public function has(string $name): bool * * @return mixed */ - public function all() + public function all(): mixed { - return Config::all(); + return ConfigFacade::all(); } /** @@ -120,10 +96,7 @@ public function create(ConfigItem $configItem): bool if ($this->has($configItem->name)) { return false; } - - $config = new Config(); - - return $this->fillColumns($config, $configItem)->save(); + return ConfigFacade::create( $configItem); } /** @@ -133,37 +106,19 @@ public function create(ConfigItem $configItem): bool * @param ConfigItem $configItem * @return mixed */ - public function update(Config $config, ConfigItem $configItem) + public function update($config, ConfigItem $configItem): mixed { - return $this->fillColumns($config, $configItem)->save(); + return ConfigFacade::update_config($configItem); } /** * Delete config parameter. * - * @param Config $config + * @param $config * @return int */ - public function delete(Config $config): int + public function delete($config): int { - return Config::destroy($config->id); - } - - /** - * Fill config paremeter columns. - * - * @param Config $config - * @param ConfigItem $configItem - * @return Config - */ - private function fillColumns(Config $config, ConfigItem $configItem): Config - { - $config->name = $configItem->name; - $config->val = $configItem->val; - $config->type = $configItem->type; - $config->description = $configItem->description; - $config->tags = $configItem->tags; - - return $config; + return ConfigFacade::delete_config($config); } } diff --git a/src/LaravelConfigServiceProvider.php b/src/LaravelConfigServiceProvider.php index b7694f4..6a2bdca 100755 --- a/src/LaravelConfigServiceProvider.php +++ b/src/LaravelConfigServiceProvider.php @@ -3,6 +3,7 @@ namespace TarfinLabs\LaravelConfig; use Illuminate\Support\ServiceProvider; +use App\Models\Config as ConfigModel; class LaravelConfigServiceProvider extends ServiceProvider { @@ -11,12 +12,11 @@ class LaravelConfigServiceProvider extends ServiceProvider */ public function boot(): void { - /* - * Optional methods to load your package assets - */ + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); if ($this->app->runningInConsole()) { + $this->publishes([ __DIR__.'/../config/config.php' => config_path('laravel-config.php'), ], 'laravel-config'); @@ -24,6 +24,13 @@ public function boot(): void $this->publishes([ __DIR__.'/../database/factories/ConfigFactory.php' => database_path('factories/ConfigFactory.php'), ], 'laravel-config-factories'); + $this->publishes([ + __DIR__.'/Traits' => app_path('Traits'), + __DIR__.'/Models' => app_path('Models'), + ], 'laravel-config-models'); + $this->commands([ + Console\InstallCommand::class, + ]); } } @@ -36,8 +43,8 @@ public function register(): void $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-config'); // Register the main class to use with the facade - $this->app->singleton('laravel-config', function () { - return new LaravelConfig; + $this->app->singleton('laravel-config', static function () { + return new ConfigModel(); }); } } diff --git a/src/Config/Config.php b/src/Models/Config.php similarity index 86% rename from src/Config/Config.php rename to src/Models/Config.php index 6eb374d..65e68a8 100644 --- a/src/Config/Config.php +++ b/src/Models/Config.php @@ -1,12 +1,15 @@ first(); + + if ($config === null) { + return null; + } + + $config->val = $value; + $config->save(); + + return $value; + } + + /** + * Set config discription with given data by id. + * + * @param int $id + * @param string $value + * @return string|null + */ + + public function set_discription_by_id(int $id, string $value): string|null + { + + + $config = parent::where('id', $id)->first(); + + if ($config === null) { + return null; + } + + $config->description = $value; + $config->save(); + + return $value; + } + /** + * Set config description with given data by id. + * + * @param int $id + * @param mixed $value + * @return array|null + */ + public function set_tags_by_id(int $id, mixed $value): mixed + { + $config = parent::where('id', $id)->first(); + + if ($config === null) { + return null; + } + + $config->tags = $value; + $config->save(); + + return $value; + } + + + /** + * Get config by given id. + * + * @param int $id + * @param mixed $default + * @return mixed + */ + public function get_by_id(int $id, mixed $default = null): mixed + { + $config = parent::where('id', $id)->first(); + + if ($config === null) { + return $default; + } + + return $config; + } + +} diff --git a/src/Traits/LaravelConfigTrait.php b/src/Traits/LaravelConfigTrait.php new file mode 100755 index 0000000..39b7495 --- /dev/null +++ b/src/Traits/LaravelConfigTrait.php @@ -0,0 +1,214 @@ +has($name)) { + return $default; + } + + $config = parent::where('name', $name)->first(); + + return $config->val; + } + /** + * Get config by given name. + * this is an alias of the get function + * for consistency + * + * @param string $name + * @param $default + * @return mixed + */ + public function get_config(string $name, $default = null): mixed + { + return $this->get($name, $default); + } + + /** + * Get nested config params. + * + * @param string $namespace + * @return Collection + */ + public function getNested(string $namespace): Collection + { + $params = parent::where('name', 'LIKE', "{$namespace}.%")->get(); + + $config = collect(); + + foreach ($params as $param) { + $keys = explode('.', str_replace("{$namespace}.", '', $param->name)); + $name = ''; + + foreach ($keys as $key) { + $name .= $key.'.'; + } + + $param->name = rtrim($name, '.'); + + $config->push($param); + } + + return $config; + } + + /** + * @param $tags + * @return Collection + */ + public function getByTag($tags): Collection|null + { + if (! is_array($tags)) { + $tags = [$tags]; + } + + return parent::whereJsonContains('tags', $tags)->get(); + } + + /** + * Set config with given data. + * + * @param string $name + * @param $value + * @return mixed + */ + public function set(string $name, $value): mixed + { + if (! $this->has($name)) { + return null; + } + + $config = parent::where('name', $name)->first(); + + $config->val = $value; + $config->save(); + + return $value; + } + + + /** + * Set config with given data. + * this is an alias of the set function + * for consistency + * @param string $name + * @param $value + * @return mixed + */ + public function set_config(string $name, $value): mixed + { + return $this->set($name, $value); + } + + + /** + * Check whether a config parameter is set. + * + * @param string $name + * @return bool + */ + public function has(string $name): bool + { + return parent::where('name', $name)->count() > 0; + } + + /** + * Check whether a config parameter is set. + * this is an alias of the has function + * for consistency + * + * @param string $name + * @return bool + */ + public function has_config(string $name): bool + { + return $this->has($name); + } + + + /** + * Create a new config parameter. + * + * @param ConfigItem $configItem + * @return bool + */ + public function create(ConfigItem $configItem): bool + { + if ($this->has($configItem->name)) { + return false; + } + + return $this->fillColumns($configItem)->save(); + } + + /** + * Create a new config parameter. + * this is an alias of the create function + * for consistency + * + * @param ConfigItem $configItem + * @return bool + */ + public function create_config(ConfigItem $configItem): bool + { + return $this->create($configItem); + } + + /** + * Update config paremeter. + * + * @param ConfigItem $configItem + * @return mixed + */ + public function update_config(ConfigItem $configItem): mixed + { + $config = parent::where('name', $configItem->name)->first(); + + return $config->fillColumns($configItem)->save(); + } + + /** + * Delete config parameter. + * + * @param Config $config + * @return int + */ + public function delete_config(parent $config): int + { + return parent::destroy($config->id); + } + + /** + * Fill config paremeter columns. + * + * @param Config $config + * @param ConfigItem $configItem + * @return parent + */ + private function fillColumns(ConfigItem $configItem): parent + { + $this->name = $configItem->name; + $this->val = $configItem->val; + $this->type = $configItem->type; + $this->description = $configItem->description; + $this->tags = $configItem->tags; + + return $this; + } +} diff --git a/src/helpers.php b/src/helpers.php index 6c26441..eddf269 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -1,6 +1,6 @@ create($configItem); } @@ -23,9 +23,9 @@ function create_config(ConfigItem $configItem) * @param string|null $key * @return mixed */ - function read_config(string $key = null) + function read_config(string|null $key = null): mixed { - if (is_null($key)) { + if ($key === null) { return app('laravel-config')->all(); } @@ -40,7 +40,7 @@ function read_config(string $key = null) * @param string|null $key * @return mixed */ - function read_nested(string $key) + function read_nested(string $key): mixed { return app('laravel-config')->getNested($key); } @@ -50,13 +50,12 @@ function read_nested(string $key) /** * Update given config item by given data. * - * @param Config $config * @param ConfigItem $configItem * @return mixed */ - function update_config(Config $config, ConfigItem $configItem) + function update_config(ConfigItem $configItem): mixed { - return app('laravel-config')->update($config, $configItem); + return app('laravel-config')->update_config($configItem); } } @@ -64,12 +63,12 @@ function update_config(Config $config, ConfigItem $configItem) /** * Delete given config item. * - * @param Config $config + * @param ConfigModel $config * @return mixed */ - function delete_config(Config $config) + function delete_config(ConfigModel $config): mixed { - return app('laravel-config')->delete($config); + return app('laravel-config')->delete_config($config); } } @@ -81,7 +80,7 @@ function delete_config(Config $config) * @param $value * @return mixed */ - function set_config_value(string $key, $value) + function set_config_value(string $key, $value): mixed { return app('laravel-config')->set($key, $value); } @@ -94,7 +93,7 @@ function set_config_value(string $key, $value) * @param string $key * @return bool */ - function has_config(string $key) + function has_config(string $key): bool { return app('laravel-config')->has($key); } diff --git a/tests/LaravelConfigOldTest.php b/tests/LaravelConfigOldTest.php new file mode 100644 index 0000000..b53bd60 --- /dev/null +++ b/tests/LaravelConfigOldTest.php @@ -0,0 +1,289 @@ +laravelConfig = new LaravelConfig(); + } + + /** @test */ + public function it_create_a_new_config_parameter(): void + { + $factory = new ConfigFactory(); + $configItem = $factory->setName(Str::random(5)) + ->setType(ConfigDataType::BOOLEAN) + ->setValue('1') + ->setDescription(Str::random(50)) + ->get(); + + $this->laravelConfig->create($configItem); + + $this->assertDatabaseHas(config('laravel-config.table'), [ + 'name' => $configItem->name, + 'val' => $configItem->val, + 'type' => $configItem->type, + 'description' => $configItem->description, + ]); + } + + /** @test */ + public function it_create_a_new_config_parameter_with_tag(): void + { + $factory = new ConfigFactory(); + $configItem = $factory->setName(Str::random(5)) + ->setType(ConfigDataType::BOOLEAN) + ->setValue('1') + ->setTags(['system']) + ->setDescription(Str::random(50)) + ->get(); + + $this->laravelConfig->create($configItem); + + $this->assertDatabaseHas(config('laravel-config.table'), [ + 'name' => $configItem->name, + 'val' => $configItem->val, + 'type' => $configItem->type, + 'description' => $configItem->description, + ]); + + $this->assertTrue($this->laravelConfig->getByTag(['system'])->count() > 0); + } + + /** @test */ + public function it_does_not_create_a_config_parameter_with_the_same_name(): void + { + $config = factory(ConfigModel::class)->create(); + $this->assertDatabaseHas(config('laravel-config.table'), ['name' => $config->name]); + + $factory = new ConfigFactory(); + $configItem = $factory->setName($config->name) + ->setType(ConfigDataType::BOOLEAN) + ->setValue('1') + ->setDescription(Str::random(50)) + ->get(); + + $response = $this->laravelConfig->create($configItem); + + $this->assertFalse($response); + } + + /** @test */ + public function it_updates_existing_config_parameter(): void + { + $config = factory(ConfigModel::class)->create(['val' => '0']); + $this->assertDatabaseHas(config('laravel-config.table'), ['name' => $config->name, 'val' => $config->val]); + + $factory = new ConfigFactory($config); + $configItem = $factory->setType(ConfigDataType::BOOLEAN) + ->setValue('0') + ->setDescription('updated-description') + ->get(); + + $this->laravelConfig->update($config, $configItem); + + $this->assertDatabaseHas(config('laravel-config.table'), [ + 'name' => $config->name, + 'val' => $configItem->val, + 'type' => $configItem->type, + 'description' => $configItem->description, + ]); + } + + /** @test */ + public function it_deletes_an_existing_config_parameter(): void + { + $name = 'dummy-name'; + $config = factory(ConfigModel::class)->create(['name' => $name]); + $this->assertDatabaseHas(config('laravel-config.table'), ['name' => $config->name]); + + $this->laravelConfig->delete($config); + + $this->assertDatabaseMissing(config('laravel-config.table'), ['name' => $name]); + } + + /** @test */ + public function it_sets_a_value_to_existing_config_parameter(): void + { + $config = factory(ConfigModel::class)->create(['val' => '1']); + + $response = $this->laravelConfig->set($config->name, '0'); + + $this->assertEquals('0', $response); + } + + /** @test */ + public function it_does_not_set_a_value_to_not_existing_config_parameter(): void + { + $response = $this->laravelConfig->set('dummy', '1'); + + $this->assertNull($response); + } + + /** @test */ + public function it_returns_a_config_parameter_value_by_given_name(): void + { + $config = factory(ConfigModel::class)->create(); + + $response = $this->laravelConfig->get($config->name); + + $this->assertEquals($config->val, $response); + } + + /** @test */ + public function it_returns_config_collection_by_tag_name(): void + { + factory(ConfigModel::class, 3) + ->create(); + + $config = factory(ConfigModel::class, 5)->create([ + 'tags' => ['system'], + ]); + + $response = $this->laravelConfig->getByTag(['system']); + + $this->assertEquals($config->count(), $response->count()); + } + + /** @test */ + public function it_does_not_return_a_not_existing_config_parameter(): void + { + $response = $this->laravelConfig->get('dummy'); + + $this->assertNull($response); + } + + /** @test */ + public function it_returns_if_a_config_parameter_is_exist(): void + { + $name = 'dummy'; + $response = $this->laravelConfig->has($name); + $this->assertFalse($response); + + factory(ConfigModel::class)->create(['name' => $name]); + $response = $this->laravelConfig->has($name); + $this->assertTrue($response); + } + + /** @test */ + public function it_returns_all_config_parameters(): void + { + factory(ConfigModel::class)->times(2)->create(); + + $response = $this->laravelConfig->all(); + + $this->assertEquals(2, $response->count()); + } + + /** @test */ + public function it_returns_nested_config_parameters(): void + { + factory(ConfigModel::class)->create([ + 'name' => 'foo.bar', + 'val' => true, + ]); + + factory(ConfigModel::class)->create([ + 'name' => 'foo.baz', + 'val' => false, + ]); + + $response = $this->laravelConfig->getNested('foo'); + + $this->assertEquals(2, $response->count()); + $this->assertEquals('bar', $response->first()->name); + $this->assertEquals('baz', $response->last()->name); + } + + /** @test */ + public function it_returns_boolean_value_for_boolean_type_config_parameter_if_exists(): void + { + $config = factory(ConfigModel::class)->create([ + 'name' => 'yunus.was.here', + 'val' => '1', + 'type' => ConfigDataType::BOOLEAN, + ]); + + $response = $this->laravelConfig->get($config->name); + + $this->assertTrue($response); + } + + /** @test */ + public function it_returns_integer_value_for_integer_type_config_parameter_if_exists(): void + { + $config = factory(ConfigModel::class)->create([ + 'name' => 'yunus.was.here', + 'val' => '123456', + 'type' => ConfigDataType::INTEGER, + ]); + + $response = $this->laravelConfig->get($config->name); + + $this->assertIsInt($response); + } + + /** @test */ + public function it_returns_datetime_value_for_datetime_type_config_parameter_if_exists(): void + { + $config = factory(ConfigModel::class)->create([ + 'name' => 'yunus.was.here', + 'val' => '2024-02-29 12:00', + 'type' => ConfigDataType::DATE_TIME, + ]); + + $response = $this->laravelConfig->get($config->name); + + $this->assertInstanceOf(Carbon::class, $response); + } + + /** @test */ + public function it_returns_date_value_for_date_type_config_parameter_if_exists(): void + { + $config = factory(ConfigModel::class)->create([ + 'name' => 'yunus.was.here', + 'val' => '2024-02-29', + 'type' => ConfigDataType::DATE, + ]); + + $response = $this->laravelConfig->get($config->name); + + $this->assertInstanceOf(Carbon::class, $response); + } + + /** @test */ + public function it_returns_json_value_for_json_type_config_parameter_if_exists(): void + { + $config = factory(ConfigModel::class)->create([ + 'name' => 'yunus.was.here', + 'val' => '{"9":[7,8,9],"2":[7,8,9],"31":[10,11,12]}', + 'type' => ConfigDataType::JSON, + ]); + + $response = $this->laravelConfig->get($config->name); + + $this->assertIsArray($response); + + $this->assertArrayHasKey(9, $response); + $this->assertArrayHasKey(2, $response); + $this->assertArrayHasKey(31, $response); + } +} diff --git a/tests/LaravelConfigTest.php b/tests/LaravelConfigTest.php index 714a139..39a1e52 100644 --- a/tests/LaravelConfigTest.php +++ b/tests/LaravelConfigTest.php @@ -4,21 +4,21 @@ use Carbon\Carbon; use Illuminate\Support\Str; -use TarfinLabs\LaravelConfig\Config\Config; +use App\Models\Config as ConfigModel; use TarfinLabs\LaravelConfig\Config\ConfigFactory; use TarfinLabs\LaravelConfig\Enums\ConfigDataType; -use TarfinLabs\LaravelConfig\LaravelConfig; + class LaravelConfigTest extends TestCase { - /** @var LaravelConfig */ + /** @var ConfigModel */ protected $laravelConfig; public function setUp(): void { parent::setUp(); - $this->laravelConfig = new LaravelConfig(); + $this->laravelConfig = new ConfigModel(); } /** @test */ @@ -67,7 +67,7 @@ public function it_create_a_new_config_parameter_with_tag(): void /** @test */ public function it_does_not_create_a_config_parameter_with_the_same_name(): void { - $config = factory(Config::class)->create(); + $config = factory(ConfigModel::class)->create(); $this->assertDatabaseHas(config('laravel-config.table'), ['name' => $config->name]); $factory = new ConfigFactory(); @@ -85,7 +85,7 @@ public function it_does_not_create_a_config_parameter_with_the_same_name(): void /** @test */ public function it_updates_existing_config_parameter(): void { - $config = factory(Config::class)->create(['val' => '0']); + $config = factory(ConfigModel::class)->create(['val' => '0']); $this->assertDatabaseHas(config('laravel-config.table'), ['name' => $config->name, 'val' => $config->val]); $factory = new ConfigFactory($config); @@ -94,7 +94,7 @@ public function it_updates_existing_config_parameter(): void ->setDescription('updated-description') ->get(); - $this->laravelConfig->update($config, $configItem); + $this->laravelConfig->update_config($configItem); $this->assertDatabaseHas(config('laravel-config.table'), [ 'name' => $config->name, @@ -108,10 +108,10 @@ public function it_updates_existing_config_parameter(): void public function it_deletes_an_existing_config_parameter(): void { $name = 'dummy-name'; - $config = factory(Config::class)->create(['name' => $name]); + $config = factory(ConfigModel::class)->create(['name' => $name]); $this->assertDatabaseHas(config('laravel-config.table'), ['name' => $config->name]); - $this->laravelConfig->delete($config); + $this->laravelConfig->delete_config($config); $this->assertDatabaseMissing(config('laravel-config.table'), ['name' => $name]); } @@ -119,7 +119,7 @@ public function it_deletes_an_existing_config_parameter(): void /** @test */ public function it_sets_a_value_to_existing_config_parameter(): void { - $config = factory(Config::class)->create(['val' => '1']); + $config = factory(ConfigModel::class)->create(['val' => '1']); $response = $this->laravelConfig->set($config->name, '0'); @@ -137,7 +137,7 @@ public function it_does_not_set_a_value_to_not_existing_config_parameter(): void /** @test */ public function it_returns_a_config_parameter_value_by_given_name(): void { - $config = factory(Config::class)->create(); + $config = factory(ConfigModel::class)->create(); $response = $this->laravelConfig->get($config->name); @@ -147,10 +147,10 @@ public function it_returns_a_config_parameter_value_by_given_name(): void /** @test */ public function it_returns_config_collection_by_tag_name(): void { - factory(Config::class, 3) + factory(ConfigModel::class, 3) ->create(); - $config = factory(Config::class, 5)->create([ + $config = factory(ConfigModel::class, 5)->create([ 'tags' => ['system'], ]); @@ -174,7 +174,7 @@ public function it_returns_if_a_config_parameter_is_exist(): void $response = $this->laravelConfig->has($name); $this->assertFalse($response); - factory(Config::class)->create(['name' => $name]); + factory(ConfigModel::class)->create(['name' => $name]); $response = $this->laravelConfig->has($name); $this->assertTrue($response); } @@ -182,7 +182,7 @@ public function it_returns_if_a_config_parameter_is_exist(): void /** @test */ public function it_returns_all_config_parameters(): void { - factory(Config::class)->times(2)->create(); + factory(ConfigModel::class)->times(2)->create(); $response = $this->laravelConfig->all(); @@ -192,12 +192,12 @@ public function it_returns_all_config_parameters(): void /** @test */ public function it_returns_nested_config_parameters(): void { - factory(Config::class)->create([ + factory(ConfigModel::class)->create([ 'name' => 'foo.bar', 'val' => true, ]); - factory(Config::class)->create([ + factory(ConfigModel::class)->create([ 'name' => 'foo.baz', 'val' => false, ]); @@ -212,7 +212,7 @@ public function it_returns_nested_config_parameters(): void /** @test */ public function it_returns_boolean_value_for_boolean_type_config_parameter_if_exists(): void { - $config = factory(Config::class)->create([ + $config = factory(ConfigModel::class)->create([ 'name' => 'yunus.was.here', 'val' => '1', 'type' => ConfigDataType::BOOLEAN, @@ -226,7 +226,7 @@ public function it_returns_boolean_value_for_boolean_type_config_parameter_if_ex /** @test */ public function it_returns_integer_value_for_integer_type_config_parameter_if_exists(): void { - $config = factory(Config::class)->create([ + $config = factory(ConfigModel::class)->create([ 'name' => 'yunus.was.here', 'val' => '123456', 'type' => ConfigDataType::INTEGER, @@ -240,7 +240,7 @@ public function it_returns_integer_value_for_integer_type_config_parameter_if_ex /** @test */ public function it_returns_datetime_value_for_datetime_type_config_parameter_if_exists(): void { - $config = factory(Config::class)->create([ + $config = factory(ConfigModel::class)->create([ 'name' => 'yunus.was.here', 'val' => '2024-02-29 12:00', 'type' => ConfigDataType::DATE_TIME, @@ -254,7 +254,7 @@ public function it_returns_datetime_value_for_datetime_type_config_parameter_if_ /** @test */ public function it_returns_date_value_for_date_type_config_parameter_if_exists(): void { - $config = factory(Config::class)->create([ + $config = factory(ConfigModel::class)->create([ 'name' => 'yunus.was.here', 'val' => '2024-02-29', 'type' => ConfigDataType::DATE, @@ -268,7 +268,7 @@ public function it_returns_date_value_for_date_type_config_parameter_if_exists() /** @test */ public function it_returns_json_value_for_json_type_config_parameter_if_exists(): void { - $config = factory(Config::class)->create([ + $config = factory(ConfigModel::class)->create([ 'name' => 'yunus.was.here', 'val' => '{"9":[7,8,9],"2":[7,8,9],"31":[10,11,12]}', 'type' => ConfigDataType::JSON, diff --git a/tests/TestCase.php b/tests/TestCase.php index b58bbd4..b6918b8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,23 +2,29 @@ namespace TarfinLabs\LaravelConfig\Tests; -use Illuminate\Support\Facades\Schema; +// use Illuminate\Support\Facades\Schema; +use Illuminate\Foundation\Testing\RefreshDatabase; use TarfinLabs\LaravelConfig\LaravelConfigServiceProvider; class TestCase extends \Orchestra\Testbench\TestCase { + use RefreshDatabase; + public function setUp(): void { parent::setUp(); $this->withFactories(__DIR__.'/../database/factories'); - Schema::dropAllTables(); + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + + // Schema::dropAllTables(); - $this->artisan('migrate', [ - '--database' => 'mysql', - '--realpath' => realpath(__DIR__.'/../database/migrations'), - ]); + // $this->artisan('migrate', [ + // '--database' => 'mysql', + // '--realpath' => realpath(__DIR__.'/../database/migrations'), + // ]); + $this->artisan('laravel-config:install'); } /** From 9307422556bb945d425c6e5896d7b4378d5f8fdb Mon Sep 17 00:00:00 2001 From: Deep-Tech Showcase and Eaglepoint Funding Date: Tue, 9 Apr 2024 17:17:37 +0300 Subject: [PATCH 2/8] Update CHANGELOG.md --- CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cf4984..755806d 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,7 @@ # Changelog All notable changes to `laravel-config` will be documented in this file. -## [Unreleased] - -## [5.1.1-EPF] -2024-04-09 +## [Unreleased] - 2024-04-09 - ### Braking Change: Made the Models and Traits Publishable, so you can add SoftDeletes, auditing, and/or caching if you want (YOU MUST RUN THE INSTALLATION COMMAND) - ### Braking Change: Check your Namespaces From d3fd10e30ed2d56c45d86cb6ae789da10f96c5fd Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 9 Apr 2024 14:26:35 +0000 Subject: [PATCH 3/8] Apply fixes from StyleCI --- database/factories/ConfigFactory.php | 4 ++-- src/Config/ConfigFactory.php | 1 - src/Console/InstallCommand.php | 1 - src/LaravelConfig.php | 7 ++++--- src/LaravelConfigServiceProvider.php | 4 +--- src/Models/Config.php | 2 +- src/Traits/LaravelConfigDataByIdTrait.php | 21 +++++++-------------- src/Traits/LaravelConfigTrait.php | 15 ++++++--------- tests/LaravelConfigOldTest.php | 6 +----- tests/LaravelConfigTest.php | 3 +-- 10 files changed, 23 insertions(+), 41 deletions(-) diff --git a/database/factories/ConfigFactory.php b/database/factories/ConfigFactory.php index 9c22c87..63f11c1 100644 --- a/database/factories/ConfigFactory.php +++ b/database/factories/ConfigFactory.php @@ -1,9 +1,9 @@ info('Laravel-config installed successfully.'); } - } diff --git a/src/LaravelConfig.php b/src/LaravelConfig.php index 24ba167..07f6476 100644 --- a/src/LaravelConfig.php +++ b/src/LaravelConfig.php @@ -3,8 +3,8 @@ namespace TarfinLabs\LaravelConfig; use Illuminate\Support\Collection; -use TarfinLabs\LaravelConfig\LaravelConfigFacade as ConfigFacade; use TarfinLabs\LaravelConfig\Config\ConfigItem; +use TarfinLabs\LaravelConfig\LaravelConfigFacade as ConfigFacade; class LaravelConfig { @@ -17,7 +17,7 @@ class LaravelConfig */ public function get(string $name, $default = null): mixed { - if (!$this->has($name)) { + if (! $this->has($name)) { return $default; } @@ -96,7 +96,8 @@ public function create(ConfigItem $configItem): bool if ($this->has($configItem->name)) { return false; } - return ConfigFacade::create( $configItem); + + return ConfigFacade::create($configItem); } /** diff --git a/src/LaravelConfigServiceProvider.php b/src/LaravelConfigServiceProvider.php index 6a2bdca..c2d09e9 100755 --- a/src/LaravelConfigServiceProvider.php +++ b/src/LaravelConfigServiceProvider.php @@ -2,8 +2,8 @@ namespace TarfinLabs\LaravelConfig; -use Illuminate\Support\ServiceProvider; use App\Models\Config as ConfigModel; +use Illuminate\Support\ServiceProvider; class LaravelConfigServiceProvider extends ServiceProvider { @@ -12,11 +12,9 @@ class LaravelConfigServiceProvider extends ServiceProvider */ public function boot(): void { - $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); if ($this->app->runningInConsole()) { - $this->publishes([ __DIR__.'/../config/config.php' => config_path('laravel-config.php'), ], 'laravel-config'); diff --git a/src/Models/Config.php b/src/Models/Config.php index 65e68a8..64dc802 100644 --- a/src/Models/Config.php +++ b/src/Models/Config.php @@ -2,8 +2,8 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; use App\Traits\LaravelConfigTrait; +use Illuminate\Database\Eloquent\Model; use TarfinLabs\LaravelConfig\Casts\ConfigValueCast; class Config extends Model diff --git a/src/Traits/LaravelConfigDataByIdTrait.php b/src/Traits/LaravelConfigDataByIdTrait.php index d68432a..4da0d2c 100644 --- a/src/Traits/LaravelConfigDataByIdTrait.php +++ b/src/Traits/LaravelConfigDataByIdTrait.php @@ -2,20 +2,17 @@ namespace App\Traits; - trait LaravelConfigDataByIdTrait { /** * Set config with given data by id. * * @param int $id - * @param mixed $value + * @param mixed $value * @return mixed */ public function set_by_id(int $id, mixed $value): mixed { - - $config = parent::where('id', $id)->first(); if ($config === null) { @@ -31,15 +28,12 @@ public function set_by_id(int $id, mixed $value): mixed /** * Set config discription with given data by id. * - * @param int $id - * @param string $value + * @param int $id + * @param string $value * @return string|null */ - public function set_discription_by_id(int $id, string $value): string|null { - - $config = parent::where('id', $id)->first(); if ($config === null) { @@ -51,11 +45,12 @@ public function set_discription_by_id(int $id, string $value): string|null return $value; } + /** * Set config description with given data by id. * * @param int $id - * @param mixed $value + * @param mixed $value * @return array|null */ public function set_tags_by_id(int $id, mixed $value): mixed @@ -72,12 +67,11 @@ public function set_tags_by_id(int $id, mixed $value): mixed return $value; } - /** * Get config by given id. * - * @param int $id - * @param mixed $default + * @param int $id + * @param mixed $default * @return mixed */ public function get_by_id(int $id, mixed $default = null): mixed @@ -90,5 +84,4 @@ public function get_by_id(int $id, mixed $default = null): mixed return $config; } - } diff --git a/src/Traits/LaravelConfigTrait.php b/src/Traits/LaravelConfigTrait.php index 39b7495..33169d7 100755 --- a/src/Traits/LaravelConfigTrait.php +++ b/src/Traits/LaravelConfigTrait.php @@ -7,7 +7,6 @@ trait LaravelConfigTrait { - /** * Get config by given name. * @@ -17,7 +16,6 @@ trait LaravelConfigTrait */ public function get(string $name, $default = null): mixed { - if (! $this->has($name)) { return $default; } @@ -26,10 +24,11 @@ public function get(string $name, $default = null): mixed return $config->val; } + /** * Get config by given name. * this is an alias of the get function - * for consistency + * for consistency. * * @param string $name * @param $default @@ -102,11 +101,11 @@ public function set(string $name, $value): mixed return $value; } - /** * Set config with given data. * this is an alias of the set function - * for consistency + * for consistency. + * * @param string $name * @param $value * @return mixed @@ -116,7 +115,6 @@ public function set_config(string $name, $value): mixed return $this->set($name, $value); } - /** * Check whether a config parameter is set. * @@ -131,7 +129,7 @@ public function has(string $name): bool /** * Check whether a config parameter is set. * this is an alias of the has function - * for consistency + * for consistency. * * @param string $name * @return bool @@ -141,7 +139,6 @@ public function has_config(string $name): bool return $this->has($name); } - /** * Create a new config parameter. * @@ -160,7 +157,7 @@ public function create(ConfigItem $configItem): bool /** * Create a new config parameter. * this is an alias of the create function - * for consistency + * for consistency. * * @param ConfigItem $configItem * @return bool diff --git a/tests/LaravelConfigOldTest.php b/tests/LaravelConfigOldTest.php index b53bd60..c302f49 100644 --- a/tests/LaravelConfigOldTest.php +++ b/tests/LaravelConfigOldTest.php @@ -2,13 +2,9 @@ namespace TarfinLabs\LaravelConfig\Tests; - - - - +use App\Models\Config as ConfigModel; use Carbon\Carbon; use Illuminate\Support\Str; -use App\Models\Config as ConfigModel; use TarfinLabs\LaravelConfig\Config\ConfigFactory; use TarfinLabs\LaravelConfig\Enums\ConfigDataType; use TarfinLabs\LaravelConfig\LaravelConfig; diff --git a/tests/LaravelConfigTest.php b/tests/LaravelConfigTest.php index 39a1e52..f24e8c8 100644 --- a/tests/LaravelConfigTest.php +++ b/tests/LaravelConfigTest.php @@ -2,13 +2,12 @@ namespace TarfinLabs\LaravelConfig\Tests; +use App\Models\Config as ConfigModel; use Carbon\Carbon; use Illuminate\Support\Str; -use App\Models\Config as ConfigModel; use TarfinLabs\LaravelConfig\Config\ConfigFactory; use TarfinLabs\LaravelConfig\Enums\ConfigDataType; - class LaravelConfigTest extends TestCase { /** @var ConfigModel */ From 528e3f777f3239a7c5c9210b26af75bff4b7cd67 Mon Sep 17 00:00:00 2001 From: Deep-Tech Showcase and Eaglepoint Funding Date: Wed, 10 Apr 2024 17:36:53 +0300 Subject: [PATCH 4/8] Update ConfigDataType.php --- src/Enums/ConfigDataType.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Enums/ConfigDataType.php b/src/Enums/ConfigDataType.php index 56b8d20..88ece9f 100644 --- a/src/Enums/ConfigDataType.php +++ b/src/Enums/ConfigDataType.php @@ -4,6 +4,9 @@ enum ConfigDataType: string { + case STRING = 'string'; + case NUMERIC = 'numeric'; + case NONE = 'None'; case INTEGER = 'integer'; case BOOLEAN = 'boolean'; case JSON = 'json'; From 281dac6cdb0fac3f090f07a64c8907ca4545c8e9 Mon Sep 17 00:00:00 2001 From: Binyamin Blatt Date: Tue, 16 Apr 2024 16:16:04 +0300 Subject: [PATCH 5/8] Console Commands to get and set configs --- src/Console/GetCommand.php | 25 +++++++++++++++++++++++++ src/Console/SetCommand.php | 26 ++++++++++++++++++++++++++ src/LaravelConfigServiceProvider.php | 2 ++ 3 files changed, 53 insertions(+) create mode 100644 src/Console/GetCommand.php create mode 100644 src/Console/SetCommand.php diff --git a/src/Console/GetCommand.php b/src/Console/GetCommand.php new file mode 100644 index 0000000..a6b12cb --- /dev/null +++ b/src/Console/GetCommand.php @@ -0,0 +1,25 @@ +argument('key')); + $this->line(print_r($value, true)); + } +} diff --git a/src/Console/SetCommand.php b/src/Console/SetCommand.php new file mode 100644 index 0000000..8052d31 --- /dev/null +++ b/src/Console/SetCommand.php @@ -0,0 +1,26 @@ +argument('key'), $this->argument('value')); + } +} diff --git a/src/LaravelConfigServiceProvider.php b/src/LaravelConfigServiceProvider.php index c2d09e9..1f7ffe7 100755 --- a/src/LaravelConfigServiceProvider.php +++ b/src/LaravelConfigServiceProvider.php @@ -28,6 +28,8 @@ public function boot(): void ], 'laravel-config-models'); $this->commands([ Console\InstallCommand::class, + Console\SetCommand::class, + Console\GetCommand::class, ]); } } From 74bffee1bcecb81c3e13c347013c5a8233843950 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 24 Apr 2024 13:04:35 +0000 Subject: [PATCH 6/8] Apply fixes from StyleCI --- src/Console/SetCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Console/SetCommand.php b/src/Console/SetCommand.php index 8052d31..0e0d71e 100644 --- a/src/Console/SetCommand.php +++ b/src/Console/SetCommand.php @@ -20,7 +20,6 @@ class SetCommand extends Command */ public function handle() { - LaravelConfig::set_config($this->argument('key'), $this->argument('value')); } } From 91ec89c0bd584558c057fa85ac648eb6918ed339 Mon Sep 17 00:00:00 2001 From: Binyamin Blatt Date: Wed, 24 Apr 2024 16:20:56 +0300 Subject: [PATCH 7/8] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 755806d..023957b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ All notable changes to `laravel-config` will be documented in this file. - Because of the Braking Changes I also added a `get_config`, `set_config`, `has_config`, and `create_config` aliases for consistency - NON Braking Change: Removed the `all` function as it's not needed anymore since it's a function of a Model - I'm adding more functions to another Trait that can be added by including it in the Model these are all traits that I've found useful +- Added comands to `get_config` and `set_config` from the console +- Added more datatypes + ## [5.1.0] - 2024-04-08 From 3b713953ab33aaea3e22331314bb7d1d79bfb02a Mon Sep 17 00:00:00 2001 From: Binyamin Blatt Date: Thu, 2 May 2024 11:35:04 +0300 Subject: [PATCH 8/8] update get comand --- src/Console/GetCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/GetCommand.php b/src/Console/GetCommand.php index a6b12cb..e743c10 100644 --- a/src/Console/GetCommand.php +++ b/src/Console/GetCommand.php @@ -20,6 +20,6 @@ class GetCommand extends Command public function handle() { $value = LaravelConfig::get_config($this->argument('key')); - $this->line(print_r($value, true)); + $this->line($value); } }