Attribute Casting: Array & JSON Casting

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'options' => 'array',
    ];
}
$user = App\User::find(1);

$options = $user->options;

$options['key'] = 'value';

$user->options = $options;

$user->save();

Attribute Casting: Array & JSON Casting — Structure map

Clickable & Draggable!

Attribute Casting: Array & JSON Casting — Related pages: