diff --git a/CHANGELOG.md b/CHANGELOG.md index ed8a41a..62d1de5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to `qcod/laravel-app-settings` will be documented in this file +## 1.5.0 - 2022-01-31 +- Laravel 9 support +- Runtime group name change using `app('app-settings')->setStorageGroup('my-storage-group')` + + ## 1.4.0 - 2020-09-24 - Laravel 8 support diff --git a/README.md b/README.md index 76af8b5..316ad77 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ If your app needs different url to access the settings page you can change from ### Use Group Setting -Many time you want to store settings in a group. With version `1.1` you can define a group name from your `config/app_settings.php`. You have a closer to return the name of group as string +Many time you want to store settings in a group. With version `1.1` you can define a group name from your `config/app_settings.php`. You have a closer or a class namespace to return the name of group as string ```php return [ @@ -156,7 +156,9 @@ return [ } ``` -In this case you can have different settings for each user. +In this case you can have different settings for each user. + +🔥 You can also set settings group at runtime using `app('app-settings')->setStorageGroup('my-storage-group')`. ### Use without UI diff --git a/composer.json b/composer.json index e0e3739..1f45ef6 100644 --- a/composer.json +++ b/composer.json @@ -1,59 +1,59 @@ { - "name": "qcod/laravel-app-settings", - "description": "A package with UI to store and manage all the settings for your application", - "homepage": "https://github.com/qcod/laravel-app-settings", - "type": "library", - "license": "MIT", - "keywords": [ - "qcod", - "laravel", - "database settings", - "db settings", - "app settings", - "setting ui", - "bootstrap", - "eloquent" - ], - "authors": [ - { - "name": "Mohd Saqueib Ansari", - "email": "saquibweb@gmail.com" - } - ], - "require": { - "php": "^7.2", - "laravel/framework": "~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0", - "qcod/laravel-settings": "~1.0" - }, - "require-dev": { - "orchestra/testbench": "3.8.*|4.*|5.*", - "mockery/mockery": "^0.9.4 || ~1.0", - "phpunit/phpunit": "^8.5" - }, - "autoload": { - "psr-4": { - "QCod\\AppSettings\\": "src/" + "name": "qcod/laravel-app-settings", + "description": "A package with UI to store and manage all the settings for your application", + "homepage": "https://github.com/qcod/laravel-app-settings", + "type": "library", + "license": "MIT", + "keywords": [ + "qcod", + "laravel", + "database settings", + "db settings", + "app settings", + "setting ui", + "bootstrap", + "eloquent" + ], + "authors": [ + { + "name": "Mohd Saqueib Ansari", + "email": "saquibweb@gmail.com" + } + ], + "require": { + "php": "^7.3|^8.0", + "laravel/framework": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", + "qcod/laravel-settings": "^1.1" }, - "files": [ - "src/helpers.php" - ] - }, - "autoload-dev": { - "psr-4": { - "QCod\\AppSettings\\Tests\\": "tests/" - } - }, - "extra": { - "laravel": { - "providers": [ - "QCod\\AppSettings\\AppSettingsServiceProvider" - ], - "aliases": { - "AppSettings": "QCod\\AppSettings\\Facade" - } + "require-dev": { + "orchestra/testbench": "4.*|5.*|6.*|^8.0|^9.0|^10.0", + "mockery/mockery": "^0.9.4 || ~1.0", + "phpunit/phpunit": "^8.5|^9.5.10|^10.5|^11.5.3" + }, + "autoload": { + "psr-4": { + "QCod\\AppSettings\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "autoload-dev": { + "psr-4": { + "QCod\\AppSettings\\Tests\\": "tests/" + } + }, + "extra": { + "laravel": { + "providers": [ + "QCod\\AppSettings\\AppSettingsServiceProvider" + ], + "aliases": { + "AppSettings": "QCod\\AppSettings\\Facade" + } + } + }, + "scripts": { + "test": "vendor/bin/phpunit" } - }, - "scripts": { - "test": "vendor/bin/phpunit" - } } diff --git a/src/Setting/AppSettings.php b/src/Setting/AppSettings.php index c6fe655..1c8bbaa 100644 --- a/src/Setting/AppSettings.php +++ b/src/Setting/AppSettings.php @@ -13,7 +13,7 @@ class AppSettings /** * @var SettingStorage */ - private $settingStorage; + protected $settingStorage; /** * AppSettings constructor. @@ -22,18 +22,37 @@ class AppSettings */ public function __construct(SettingStorage $settingStorage) { - $groupName = $this->getSettingsGroupName(); + $this->setSettingStorage($settingStorage); + } + + /** + * Sets the settings storage. + * + * @param SettingStorage $settingStorage + */ + public function setSettingStorage(SettingStorage $settingStorage) + { + $this->settingStorage = $settingStorage; + $groupName = $this->getSettingsGroupName(); if( $groupName && is_callable($groupName) ) { $groupName = $this->runCallback($groupName, 'setting_group', null); - $this->settingStorage = $settingStorage->group($groupName); - } else { - $this->settingStorage = $settingStorage; + $this->setStorageGroup($groupName); } } /** - * Get al the settings from storage + * Sets the current storage group. + * + * @param string $groupName + */ + public function setStorageGroup($groupName) + { + $this->settingStorage->group($groupName); + } + + /** + * Get all the settings from storage * * @param bool $fresh * @return \Illuminate\Support\Collection @@ -214,7 +233,7 @@ public function getValidationRules() * @param bool $out * @return bool|int|mixed|string */ - private function castValue($dataType, $value, $out = false) + protected function castValue($dataType, $value, $out = false) { switch ($dataType) { case 'array': @@ -285,7 +304,7 @@ protected function cleanUpSettings($allDefinedSettings) * @param $out * @return array|mixed|string */ - private function castToArray($value, $out) + protected function castToArray($value, $out) { if ($out) { return empty($value) ? [] : json_decode($value, true); @@ -301,7 +320,7 @@ private function castToArray($value, $out) * @param $request Request * @return string|null */ - private function uploadFile($setting, $request) + protected function uploadFile($setting, $request) { $settingName = Arr::get($setting, 'name'); @@ -337,7 +356,7 @@ private function uploadFile($setting, $request) * @param $oldFile * @param $disk */ - private function deleteFile($oldFile, $disk): void + protected function deleteFile($oldFile, $disk): void { if ($oldFile && Storage::disk($disk)->exists($oldFile)) { Storage::disk($disk)->delete($oldFile); diff --git a/src/config/app_settings.php b/src/config/app_settings.php index 2f354be..b33bc81 100644 --- a/src/config/app_settings.php +++ b/src/config/app_settings.php @@ -64,6 +64,12 @@ // Any middleware you want to run on above route 'middleware' => [], + // Route Names + 'route_names' => [ + 'index' => 'settings.index', + 'store' => 'settings.store', + ], + // View settings 'setting_page_view' => 'app_settings::settings_page', 'flash_partial' => 'app_settings::_flash', diff --git a/src/routes/web.php b/src/routes/web.php index d1c3b7d..65d8ec7 100644 --- a/src/routes/web.php +++ b/src/routes/web.php @@ -3,6 +3,6 @@ Route::group([ 'middleware' => array_merge(['web'], config('app_settings.middleware', [])) ], function () { - Route::get(config('app_settings.url'), config('app_settings.controller').'@index'); - Route::post(config('app_settings.url'), config('app_settings.controller').'@store'); + Route::get(config('app_settings.url'), config('app_settings.controller').'@index')->name(config('app_settings.route_names.index')); + Route::post(config('app_settings.url'), config('app_settings.controller').'@store')->name(config('app_settings.route_names.store')); });