ldc-legaulois/app/Http/Resources/CustomerCrmResource.php
2021-03-20 14:38:15 +01:00

39 lines
1,018 B
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\Customers;
class CustomerCrmResource extends JsonResource
{
/** @var Customer */
private $customer;
public function __construct(Customers $customer)
{
$this->customer = $customer;
}
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
$crmCustomer = (object)$this->customer->apiData;
return [
'crm_id' => $this->customer->crm_id,
'firstname' => $crmCustomer->firstname,
'lastname' => $crmCustomer->lastname,
'optin' => null,
'birthdate' => null,
'phone' => $crmCustomer->phone,
'address' => $crmCustomer->address,
'address2' => null,
'city' => $crmCustomer->city,
'postcode' => $crmCustomer->postcode
];
}
}