Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model Class Overwrite #134

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/SettingsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Backpack\Settings;

use Backpack\Settings\app\Models\Setting;
use Config;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Schema;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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
Expand All @@ -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));
}
}
2 changes: 1 addition & 1 deletion src/app/Http/Controllers/SettingCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
}
Expand Down
14 changes: 12 additions & 2 deletions src/config/backpack/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
*/
'table_name' => 'settings',

/*
|--------------------------------------------------------------------------
| Model Name
|--------------------------------------------------------------------------
|
| Settings Eloquent Model Class
|
*/
'model' => \Backpack\Settings\app\Models\Setting::class,

/*
|--------------------------------------------------------------------------
| Route
Expand All @@ -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',
Expand Down