Files
portal-api/app/Support/CustomerBillingProfile.php
T

31 lines
890 B
PHP

<?php
namespace App\Support;
use App\Models\Customer;
class CustomerBillingProfile
{
public const FIELDS = ['invoice_company', 'tax_code', 'invoice_address', 'invoice_email'];
public static function payload(Customer $customer): array
{
return [
'invoice_company' => $customer->invoice_company,
'tax_code' => $customer->tax_code,
'invoice_address' => $customer->invoice_address,
'invoice_email' => $customer->invoice_email,
];
}
public static function save(Customer $customer, array $input): array
{
$customer->update(array_map(
fn ($value) => is_string($value) && trim($value) === '' ? null : $value,
array_intersect_key($input, array_flip(self::FIELDS)) + array_fill_keys(self::FIELDS, null),
));
return self::payload($customer->fresh());
}
}