1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Casts/QuickbooksSettingsCast.php
2024-09-23 07:27:28 +10:00

37 lines
960 B
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Casts;
use App\DataMapper\QuickbooksSettings;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
class QuickbooksSettingsCast implements CastsAttributes
{
public function get($model, string $key, $value, array $attributes)
{
if (is_null($value))
return new QuickbooksSettings();
$data = json_decode($value, true);
return QuickbooksSettings::fromArray($data);
}
public function set($model, string $key, $value, array $attributes)
{
if ($value instanceof QuickbooksSettings) {
return json_encode(get_object_vars($value));
}
return json_encode($value);
}
}