ldc-crm/app/Http/Resources/CustomerResource.php
Alexis Gousseau 303834bbca
Crm V4
- Make all tests pass Client (V4),CRMV2,CRMV4
- Simplify client submodule path
- Move App_url to .env.testing
2023-10-06 16:37:29 +02:00

57 lines
1.7 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CustomerResource extends JsonResource
{
/** @var integer */
private $brandId;
/**
* @param mixed $resource
* @param integer $brandId
*/
public function __construct(mixed $resource, int $brandId)
{
parent::__construct($resource);
$this->brandId = $brandId;
}
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
public function toArray(Request $request): array
{
//phpcs:disable
/** @var \App\Models\CustomerInfo */
$infos = $this->infos()->where('brand_id', $this->brandId)->first();
/** @var \App\Models\CustomerLogin */
$login = $this->logins()->where('brand_id', $this->brandId)->first();
return [
'status' => 'OK',
'user' => [
'crm_id' => $this->id,
'firstname' => $infos->firstname,
'lastname' => $infos->lastname,
'email' => $this->email,
'birth_date' => $infos->birth_date,
'address' => $infos->address,
'address2' => $infos->address2,
'phone' => $infos->phone,
'country' => $infos->country->label(),
'city' => $infos->city,
'postcode' => $infos->postcode,
'opt_in' => $infos->opt_in,
'hashcode' => $infos->hashcode,
'status' => $login->status,
]
];
}
}