From d7dbfa86d1620473cc9a5c73fe4a09e0978ddca7 Mon Sep 17 00:00:00 2001 From: Mohammad Hafijul Islam Date: Wed, 20 Mar 2024 18:01:31 +0600 Subject: [PATCH 1/5] Update settings.php Adding an option so that users can overwrite the default model class to boot for setting. --- src/config/backpack/settings.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/config/backpack/settings.php b/src/config/backpack/settings.php index 5cdf96c..4caa768 100644 --- a/src/config/backpack/settings.php +++ b/src/config/backpack/settings.php @@ -12,6 +12,16 @@ */ 'table_name' => 'settings', + /* + |-------------------------------------------------------------------------- + | Model Name + |-------------------------------------------------------------------------- + | + | Settings Eloquent Model Class + | + */ + 'model' => \Backpack\Settings\app\Models\Setting::class, + /* |-------------------------------------------------------------------------- | Route @@ -28,11 +38,11 @@ |-------------------------------------------------------------------------- | | The prefix used to add your settings into the configuration array. - | With this default you can grab your settings with: config('settings.your_setting_key') + | With this default you can grab your settings with config('settings.your_setting_key') | | WARNING: WE ADVISE TO NOT LEAVE THIS EMPTY / CHECK IF IT DOES NOT CONFLICT WITH OTHER CONFIG FILE NAMES | - | - if you leave this empty and your keys match other configuration files you might ovewrite them. + | - if you leave this empty and your keys match other configuration files you might ovetwrite them. | */ 'config_prefix' => 'settings', From 74bc7a86b0e55fb88a74c43e9fb246d4ef896fe5 Mon Sep 17 00:00:00 2001 From: Mohammad Hafijul Islam Date: Wed, 20 Mar 2024 18:03:49 +0600 Subject: [PATCH 2/5] Added the model value pulled from configuration insist of hard code. Added the model value pulled from configuration insist of hard code. --- src/app/Http/Controllers/SettingCrudController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/Http/Controllers/SettingCrudController.php b/src/app/Http/Controllers/SettingCrudController.php index e12596a..4beb3ef 100644 --- a/src/app/Http/Controllers/SettingCrudController.php +++ b/src/app/Http/Controllers/SettingCrudController.php @@ -12,7 +12,7 @@ class SettingCrudController extends CrudController public function setup() { - CRUD::setModel("Backpack\Settings\app\Models\Setting"); + CRUD::setModel(config('backpack.settings.model',\Backpack\Settings\app\Models\Setting::class)); CRUD::setEntityNameStrings(trans('backpack::settings.setting_singular'), trans('backpack::settings.setting_plural')); CRUD::setRoute(backpack_url(config('backpack.settings.route'))); } From 7e7c41999f0399dbb5043f395018c4124dd9674f Mon Sep 17 00:00:00 2001 From: Mohammad Hafijul Islam Date: Wed, 20 Mar 2024 18:41:23 +0600 Subject: [PATCH 3/5] Change the model class to configuration Now what user will set on config will reflect on service provider boot method also. --- src/SettingsServiceProvider.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/SettingsServiceProvider.php b/src/SettingsServiceProvider.php index 365ca5f..31c1bf3 100644 --- a/src/SettingsServiceProvider.php +++ b/src/SettingsServiceProvider.php @@ -2,7 +2,6 @@ namespace Backpack\Settings; -use Backpack\Settings\app\Models\Setting; use Config; use Illuminate\Routing\Router; use Illuminate\Support\Facades\Schema; @@ -42,8 +41,11 @@ public function boot() // only use the Settings package if the Settings table is present in the database if (!\App::runningInConsole() && Schema::hasTable(config('backpack.settings.table_name'))) { + //get the model class from configuration + $modelClass = \Config::get('backpack.settings.model', \Backpack\Settings\app\Models\Setting::class); + // get all settings from the database - $settings = Setting::all(); + $settings = $modelClass::all(); $config_prefix = config('backpack.settings.config_prefix'); From b4b7754cbb1f4c6170b71634492c8f888bbababa Mon Sep 17 00:00:00 2001 From: Jorge <44643608+jcastroa87@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:57:15 -0300 Subject: [PATCH 4/5] Update src/config/backpack/settings.php Co-authored-by: Pedro Martins --- src/config/backpack/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/backpack/settings.php b/src/config/backpack/settings.php index 4caa768..a61d7ac 100644 --- a/src/config/backpack/settings.php +++ b/src/config/backpack/settings.php @@ -42,7 +42,7 @@ | | WARNING: WE ADVISE TO NOT LEAVE THIS EMPTY / CHECK IF IT DOES NOT CONFLICT WITH OTHER CONFIG FILE NAMES | - | - if you leave this empty and your keys match other configuration files you might ovetwrite them. + | - if you leave this empty and your keys match other configuration files you might overwrite them. | */ 'config_prefix' => 'settings', From 51a76dc408813c8cd0c855768bf898ed62d5e1f6 Mon Sep 17 00:00:00 2001 From: Mohammad Hafijul Islam Date: Thu, 21 Mar 2024 23:54:41 +0600 Subject: [PATCH 5/5] Service provider alias to configured model option added --- src/SettingsServiceProvider.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SettingsServiceProvider.php b/src/SettingsServiceProvider.php index 31c1bf3..b2d492d 100644 --- a/src/SettingsServiceProvider.php +++ b/src/SettingsServiceProvider.php @@ -10,7 +10,7 @@ class SettingsServiceProvider extends ServiceProvider { /** - * Indicates if loading of the provider is deferred. + * Indicates if the loading of the provider is deferred. * * @var bool */ @@ -41,7 +41,7 @@ public function boot() // only use the Settings package if the Settings table is present in the database if (!\App::runningInConsole() && Schema::hasTable(config('backpack.settings.table_name'))) { - //get the model class from configuration + //get the model class from the configuration $modelClass = \Config::get('backpack.settings.model', \Backpack\Settings\app\Models\Setting::class); // get all settings from the database @@ -77,7 +77,7 @@ public function boot() */ public function setupRoutes(Router $router) { - // by default, use the routes file provided in vendor + // by default, use the routes file provided in the vendor $routeFilePathInUse = __DIR__.$this->routeFilePath; // but if there's a file with the same name in routes/backpack, use that one @@ -97,6 +97,6 @@ public function register() { // register their aliases $loader = \Illuminate\Foundation\AliasLoader::getInstance(); - $loader->alias('Setting', \Backpack\Settings\app\Models\Setting::class); + $loader->alias('Setting', config('backpack.settings.model',\Backpack\Settings\app\Models\Setting::class)); } }