This repository was archived by the owner on Apr 20, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ $user->settings('some.setting'); // Quicker access.
58
58
$user = App\User::first();
59
59
60
60
$user->settings()->set('some.setting', 'new value');
61
+ $user->settings()->update('some.setting', 'new value');
61
62
```
62
63
63
64
##### 4.) Determine if the model has a specific setting.
@@ -72,6 +73,7 @@ $user->settings()->has('some.setting');
72
73
$user = App\User::first();
73
74
74
75
$user->settings()->delete('some.setting');
76
+ $user->settings()->forget('some.setting');
75
77
```
76
78
77
79
## License
Original file line number Diff line number Diff line change @@ -29,11 +29,12 @@ public function setSettingsAttribute($settings)
29
29
/**
30
30
* The model's settings.
31
31
*
32
- * @param null $key
32
+ * @param string|null $key
33
+ * @param mixed|null $default
33
34
* @return Settings
34
35
*/
35
- public function settings ($ key = null )
36
+ public function settings ($ key = null , $ default = null )
36
37
{
37
- return $ key ? $ this ->settings ()->get ($ key ) : new Settings ($ this );
38
+ return $ key ? $ this ->settings ()->get ($ key, $ default ) : new Settings ($ this );
38
39
}
39
40
}
Original file line number Diff line number Diff line change @@ -64,6 +64,18 @@ public function delete($path = null)
64
64
return $ this ->apply ($ settings );
65
65
}
66
66
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
+
67
79
/**
68
80
* Return the value of the setting at the given path.
69
81
*
@@ -107,4 +119,17 @@ public function set($path = null, $value = [])
107
119
108
120
return $ this ->apply ($ settings );
109
121
}
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
+ }
110
135
}
You can’t perform that action at this time.
0 commit comments