Skip to content
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
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ $siteTItle = Settings::get('site_title');
$siteTitle = Settings::get('site_title', 'Your Default Awesome Website');
```

### Forget a global setting
### Delete a global setting

Now, if you want to delete the setting

```php
use RuangDeveloper\LaravelSettings\Facades\Settings;

Settings::delete('site_title');
```

### Forget a global setting (deprecated, use delete instead)

Now, if you want to delete the setting

Expand Down Expand Up @@ -120,7 +130,14 @@ $isSubscribed = $user->getSetting('subscribe_newsletter', false);
//
```

**Forget a setting**
**Delete a setting**

```php
$user = App\Models\User::find(1);
$user->deleteSetting('subscribe_newsletter');
```

**Forget a setting (deprecated, use delete instead)**

```php
$user = App\Models\User::find(1);
Expand Down
26 changes: 26 additions & 0 deletions src/Services/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function get(string $key, mixed $default = null): mixed
/**
* Forget a setting value.
*
* @deprecated Use delete() instead.
* @param string $key
* @return void
*/
Expand All @@ -60,6 +61,17 @@ public function forget(string $key): void
$this->deleteSetting($key);
}

/**
* Delete a setting item.
*
* @param string $key
* @return void
*/
public function delete(string $key): void
{
$this->deleteSetting($key);
}

/**
* Set a setting value with model.
*
Expand Down Expand Up @@ -91,6 +103,7 @@ public function getWithModel(string $key, string $modelType, mixed $modelId, mix
/**
* Forget a setting value with model.
*
* @deprecated Use deleteWithModel() instead.
* @param string $key
* @param string $modelType
* @param mixed $modelId
Expand All @@ -101,6 +114,19 @@ public function forgetWithModel(string $key, string $modelType, mixed $modelId):
$this->deleteSetting($key, $modelType, $modelId);
}

/**
* Delete a setting item with model.
*
* @param string $key
* @param string $modelType
* @param mixed $modelId
* @return void
*/
public function deleteWithModel(string $key, string $modelType, mixed $modelId): void
{
$this->deleteSetting($key, $modelType, $modelId);
}

/**
* Store a setting value.
*
Expand Down
22 changes: 22 additions & 0 deletions src/Traits/HasSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function getSetting(string $key, mixed $default = null): mixed
/**
* Forget a setting value.
*
* @deprecated Use deleteSetting() instead.
* @param string $key
* @return void
*/
Expand All @@ -109,4 +110,25 @@ public function forgetSetting(string $key): void
Cache()->forget(Support::getCacheKey($key, $this->getMorphClass(), $this->getKey()));
}
}

/**
* Delete a setting item
*
* @param string $key
* @return void
*/
public function deleteSetting(string $key): void
{
$this->settings()->where(
[
config('laravel-settings.key_name') => $key,
config('laravel-settings.morph_type') => $this->getMorphClass(),
config('laravel-settings.morph_id') => $this->getKey(),
]
)->delete();

if (config('laravel-settings.with_cache')) {
Cache()->forget(Support::getCacheKey($key, $this->getMorphClass(), $this->getKey()));
}
}
}