File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
All notable changes to ` glorand/laravel-model-settings ` will be documented in this file
4
4
5
+ ## 3.4.2 - 2019-09-25
6
+ ### Added
7
+ - Manage array type settings
5
8
6
9
## 3.4.1 - 2019-09-17
7
10
### Added
Original file line number Diff line number Diff line change @@ -20,6 +20,13 @@ trait HasSettingsField
20
20
21
21
private $ persistSettings = null ;
22
22
23
+ protected static function bootHasSettingsField ()
24
+ {
25
+ static ::saving (function (self $ model ) {
26
+ $ model ->fixSettingsValue ();
27
+ });
28
+ }
29
+
23
30
/**
24
31
* @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
25
32
* @throws ModelSettingsException
@@ -29,6 +36,17 @@ public function settings(): SettingsManagerContract
29
36
return new FieldSettingsManager ($ this );
30
37
}
31
38
39
+ public function fixSettingsValue ()
40
+ {
41
+ $ settingsFieldName = $ this ->getSettingsFieldName ();
42
+ $ attributes = $ this ->getAttributes ();
43
+ if (Arr::has ($ attributes , $ settingsFieldName )) {
44
+ if (is_array ($ this ->$ settingsFieldName )) {
45
+ $ this ->$ settingsFieldName = json_encode ($ this ->$ settingsFieldName );
46
+ }
47
+ }
48
+ }
49
+
32
50
/**
33
51
* @return array
34
52
* @throws ModelSettingsException
Original file line number Diff line number Diff line change @@ -35,6 +35,14 @@ public function testInit()
35
35
$ this ->assertTrue (array_key_exists (HasSettingsField::class, $ traits ));
36
36
}
37
37
38
+ public function testModelArraySettings ()
39
+ {
40
+ $ testArray = ['a ' => 'b ' ];
41
+ $ this ->model ->settings = $ testArray ;
42
+ $ this ->model ->save ();
43
+ $ this ->assertEquals ($ this ->model ->settings ()->all (), $ testArray );
44
+ }
45
+
38
46
/**
39
47
* @throws \Glorand\Model\Settings\Exceptions\ModelSettingsException
40
48
*/
You can’t perform that action at this time.
0 commit comments