ldc-boutique-cnc/app/Http/Resources/CustomerCrmResource.php
2023-03-09 11:58:40 +01:00

47 lines
1.3 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\Customer\Customer;
class CustomerCrmResource extends JsonResource
{
/** @var \App\Models\Customer\Customer */
private $customer;
/**
* CustomerCrmResource
*
* @param \App\Models\Customer $customer
*/
public function __construct(Customer $customer)
{
$this->customer = $customer;
}
/**
* Transform the resource into an array.
*
* @param mixed $request
* @return array
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
public function toArray($request)
{
// phpcs:enable
/** @var \LDC\LDCCRM\Models\Customer */
$crmCustomer = (object)$this->customer->apiData;
return [
'hashcode' => $this->customer->hashcode,
'firstname' => $crmCustomer->firstname,
'lastname' => $crmCustomer->lastname,
'opt_in' => $crmCustomer->opt_in,
'birthdate' => $crmCustomer->birth_date,
'phone' => $crmCustomer->phone,
'address' => $crmCustomer->address,
'address2' => $crmCustomer->address2,
'city' => $crmCustomer->city,
'postcode' => $crmCustomer->postcode
];
}
}