Eloquent\Dialect\Json::setJsonAttribute PHP Метод

setJsonAttribute() публичный Метод

Set a given attribute on the known JSON elements.
public setJsonAttribute ( string $attribute, string $key, mixed $value )
$attribute string
$key string
$value mixed
    public function setJsonAttribute($attribute, $key, $value)
    {
        // Pull the attribute and decode it
        $decoded = json_decode($this->{$attribute});
        switch (gettype($decoded)) {
            // It's possible the attribute doesn't exist yet (since we can hint at
            // structure). In that case we build an object to set values on as a
            // starting point
            case 'NULL':
                $decoded = json_decode('{}');
                $decoded->{$key} = $value;
                break;
            case 'array':
                $decoded[$key] = $value;
                break;
            default:
                $decoded->{$key} = $value;
                break;
        }
        $this->flagJsonAttribute($key, $attribute);
        $this->{$attribute} = json_encode($decoded);
        return;
    }