diff --git a/src/SettingsServiceProvider.php b/src/SettingsServiceProvider.php index 365ca5f..b2d492d 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; @@ -11,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 */ @@ -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 the 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'); @@ -75,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 @@ -95,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)); } } 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'))); } diff --git a/src/config/backpack/settings.php b/src/config/backpack/settings.php index 5cdf96c..a61d7ac 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 overwrite them. | */ 'config_prefix' => 'settings',