==== Create a custom Eloquent cast to turn attributes into rich “value objects” (or any complex type) automatically. Implement the CastsAttributes interface (or Castable) in a class with get() and set() methods, then register it on your model’s $casts: ```php // app/Casts/JsonSettingsCast.php namespace App\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class JsonSettingsCast implements CastsAttributes { public function get($model, string $key, $value, array $attributes) { return new SettingsCollection(json_decode($value, true)); } public function set($model, string $key, $value, array $attributes) { return [$key => json_encode( $value instanceof SettingsCollection ? $value->toArray() : (array) $value )]; } } ``` ```php // In your model protected $casts = [ 'settings' => \App\Casts\JsonSettingsCast::class, ]; ``` Now `$model->settings` is always a SettingsCollection, and serialization is handled for you.