Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit 13b71cf

Browse files
committed
add update and forget aliases
1 parent d459aea commit 13b71cf

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ $user->settings('some.setting'); // Quicker access.
5858
$user = App\User::first();
5959
6060
$user->settings()->set('some.setting', 'new value');
61+
$user->settings()->update('some.setting', 'new value');
6162
```
6263

6364
##### 4.) Determine if the model has a specific setting.
@@ -72,6 +73,7 @@ $user->settings()->has('some.setting');
7273
$user = App\User::first();
7374
7475
$user->settings()->delete('some.setting');
76+
$user->settings()->forget('some.setting');
7577
```
7678

7779
## License

src/HasSettings.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ public function setSettingsAttribute($settings)
2929
/**
3030
* The model's settings.
3131
*
32-
* @param null $key
32+
* @param string|null $key
33+
* @param mixed|null $default
3334
* @return Settings
3435
*/
35-
public function settings($key = null)
36+
public function settings($key = null, $default = null)
3637
{
37-
return $key ? $this->settings()->get($key) : new Settings($this);
38+
return $key ? $this->settings()->get($key, $default) : new Settings($this);
3839
}
3940
}

src/Settings.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ public function delete($path = null)
6464
return $this->apply($settings);
6565
}
6666

67+
/**
68+
* Forget the setting at the given path.
69+
*
70+
* @alias delete()
71+
* @param null $path
72+
* @return array
73+
*/
74+
public function forget($path = null)
75+
{
76+
return $this->delete($path);
77+
}
78+
6779
/**
6880
* Return the value of the setting at the given path.
6981
*
@@ -107,4 +119,17 @@ public function set($path = null, $value = [])
107119

108120
return $this->apply($settings);
109121
}
122+
123+
/**
124+
* Update the setting at the given path if it exists.
125+
*
126+
* @alias set()
127+
* @param string $path
128+
* @param mixed $value
129+
* @return $this|array
130+
*/
131+
public function update($path, $value)
132+
{
133+
return $this->set($path, $value);
134+
}
110135
}

0 commit comments

Comments
 (0)