casts in model laravel code example
Example: casts in model laravel
Once the cast is defined, you may access
the options attribute and
it will automatically be deserialized
from JSON into a PHP array. When you set
the value of the options attribute, the given
array will automatically be serialized back into
JSON for storage:
use App\Models\User;
$user = User::find(1);
$options = $user->options;
$options['key'] = 'value';
$user->options = $options;
$user->save();