Skip to content

Commit 1175103

Browse files
authored
Update docs (#48)
1 parent 0543a7e commit 1175103

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/advanced-usage/custom-generators.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,31 @@ After defining your class, you need to add it the settings config file:
138138
// config/settings.php
139139
'value_serializer' => CustomValueSerializer::class,
140140
```
141+
142+
### Unserializing Objects
143+
144+
When using the default `ValueSerializer`, we will use php's `unserialize` method to re-hydrate the value. However, we use the `allowed_classes` option to prevent
145+
objects from being unserialized back into their original form. This means that if you are storing something like an eloquent model as a setting, it will be unserialized
146+
into something like this:
147+
148+
```php
149+
__PHP_Incomplete_Class(App\Models\User) {...}
150+
```
151+
152+
Because of this, you will not have access to any kind of method or property on the model. As of `v3.3.0` of this package, you can now define a safelist of classes that
153+
should be allowed to be unserialized by settings. By default, we'll allow Carbon (date) classes to be unserialized. You can modify the safelist in the config to allow
154+
the user model from above to be unserialized as well:
155+
156+
```php
157+
// config/settings.php
158+
'unserialize_safelist' => [
159+
\Carbon\Carbon::class,
160+
\Carbon\CarbonImmutable::class,
161+
\Illuminate\Support\Carbon::class,
162+
163+
// Add this line
164+
App\Models\User::class,
165+
],
166+
```
167+
168+
> {note} You will need to safelist each Eloquent model class that you wish to be unserialized. It is not enough to safelist the base class of Model::class.

0 commit comments

Comments
 (0)