2024-08-26 01:49:22 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-09-22 23:27:28 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2024-08-26 01:49:22 +02:00
|
|
|
*
|
|
|
|
* @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)
|
|
|
|
{
|
2024-09-22 23:27:28 +02:00
|
|
|
if (is_null($value))
|
2024-09-22 23:16:34 +02:00
|
|
|
return new QuickbooksSettings();
|
2024-08-26 08:14:54 +02:00
|
|
|
|
2024-09-22 23:16:34 +02:00
|
|
|
$data = json_decode($value, true);
|
|
|
|
return QuickbooksSettings::fromArray($data);
|
2024-08-26 01:49:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function set($model, string $key, $value, array $attributes)
|
|
|
|
{
|
2024-09-22 23:16:34 +02:00
|
|
|
if ($value instanceof QuickbooksSettings) {
|
|
|
|
return json_encode(get_object_vars($value));
|
|
|
|
}
|
|
|
|
|
|
|
|
return json_encode($value);
|
2024-08-26 01:49:22 +02:00
|
|
|
}
|
|
|
|
}
|