Skip to content

Commit 241b0e8

Browse files
committed
Refactor Setanjo package: Remove model macro configuration and adjust naming conventions for consistency
1 parent 33acb73 commit 241b0e8

File tree

3 files changed

+16
-33
lines changed

3 files changed

+16
-33
lines changed

config/setanjo.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,6 @@
7070
// App\Models\User::class,
7171
],
7272

73-
/*
74-
|--------------------------------------------------------------------------
75-
| Model Macro
76-
|--------------------------------------------------------------------------
77-
|
78-
| Enable or disable the automatic registration of Eloquent model macros.
79-
| When enabled, adds 'settings()' method to all Eloquent models for
80-
| easy access to tenant-specific settings.
81-
|
82-
| Example: $user->settings()->get('theme', 'light')
83-
|
84-
*/
85-
86-
'enable_model_macro' => env('SETANJO_ENABLE_MODEL_MACRO', true),
87-
8873
/*
8974
|--------------------------------------------------------------------------
9075
| Cache Configuration

src/SetanjoServiceProvider.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class SetanjoServiceProvider extends PackageServiceProvider
1414
public function configurePackage(Package $package): void
1515
{
1616
$package
17-
->name('Setanjo')
18-
->hasConfigFile()
17+
->name('setanjo')
18+
->hasConfigFile('setanjo')
1919
->hasMigration('create_setanjo_settings_table')
2020
->hasCommands([
2121
ClearCacheCommand::class,
@@ -27,7 +27,7 @@ public function packageRegistered(): void
2727
{
2828
// Register repository binding
2929
$this->app->bind(SettingsRepositoryInterface::class, function ($app) {
30-
$driver = config('Setanjo.repository', 'database');
30+
$driver = config('setanjo.repository', 'database');
3131

3232
return match ($driver) {
3333
'database' => new DatabaseSettingsRepository,
@@ -43,19 +43,4 @@ public function packageRegistered(): void
4343
// Register alias
4444
$this->app->alias('Setanjo', SetanjoManager::class);
4545
}
46-
47-
public function packageBooted(): void
48-
{
49-
// Add model macro for easy settings access
50-
if (config('Setanjo.enable_model_macro', true)) {
51-
$this->addModelMacro();
52-
}
53-
}
54-
55-
protected function addModelMacro(): void
56-
{
57-
\Illuminate\Database\Eloquent\Model::macro('settings', function () {
58-
return app('Setanjo')->for($this);
59-
});
60-
}
6146
}

src/Traits/HasSettings.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Ahs12\Setanjo\Traits;
4+
5+
use Ahs12\Setanjo\SetanjoManager;
6+
7+
trait HasSettings
8+
{
9+
public function settings(): SetanjoManager
10+
{
11+
return app('setanjo')->for($this);
12+
}
13+
}

0 commit comments

Comments
 (0)