ldc-jeusselin/app/Http/Resources/CustomerCrmResource.php

46 lines
1.3 KiB
PHP

<?php
namespace App\Http\Resources;
use App\Models\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class CustomerCrmResource extends JsonResource
{
/** @var \App\Models\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)
{
/** @var \LDC\LDCCRM\Models\Customer */
$crmCustomer = $this->customer->api_data;
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
];
}
}