2020-12-01 17:02:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
|
2023-09-06 17:24:53 +02:00
|
|
|
use Illuminate\Http\Request;
|
2020-12-01 17:02:10 +01:00
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
|
|
class CustomerResource extends JsonResource
|
|
|
|
|
{
|
2021-12-19 15:57:24 +01:00
|
|
|
/** @var integer */
|
2020-12-01 17:02:10 +01:00
|
|
|
private $brandId;
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
2023-09-06 17:24:53 +02:00
|
|
|
* @param mixed $resource
|
|
|
|
|
* @param integer $brandId
|
2021-12-19 15:57:24 +01:00
|
|
|
*/
|
2023-09-06 17:24:53 +02:00
|
|
|
public function __construct(mixed $resource, int $brandId)
|
2021-02-28 12:04:49 +01:00
|
|
|
{
|
2020-12-01 17:02:10 +01:00
|
|
|
parent::__construct($resource);
|
|
|
|
|
$this->brandId = $brandId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Transform the resource into an array.
|
|
|
|
|
*
|
2023-09-06 17:24:53 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2020-12-01 17:02:10 +01:00
|
|
|
* @return array
|
2023-09-06 17:24:53 +02:00
|
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
2020-12-01 17:02:10 +01:00
|
|
|
*/
|
2023-09-06 17:24:53 +02:00
|
|
|
public function toArray(Request $request): array
|
2020-12-01 17:02:10 +01:00
|
|
|
{
|
2023-09-06 17:24:53 +02:00
|
|
|
//phpcs:disable
|
|
|
|
|
/** @var \App\Models\CustomerInfo */
|
2020-12-01 17:02:10 +01:00
|
|
|
$infos = $this->infos()->where('brand_id', $this->brandId)->first();
|
2023-09-06 17:24:53 +02:00
|
|
|
/** @var \App\Models\CustomerLogin */
|
2020-12-01 17:02:10 +01:00
|
|
|
$login = $this->logins()->where('brand_id', $this->brandId)->first();
|
|
|
|
|
return [
|
2020-12-02 19:16:22 +01:00
|
|
|
'status' => 'OK',
|
|
|
|
|
'user' => [
|
2023-09-06 17:24:53 +02:00
|
|
|
'crm_id' => $this->id,
|
|
|
|
|
'firstname' => $infos->firstname,
|
|
|
|
|
'lastname' => $infos->lastname,
|
|
|
|
|
'email' => $this->email,
|
2020-12-02 19:16:22 +01:00
|
|
|
'birth_date' => $infos->birth_date,
|
2023-09-06 17:24:53 +02:00
|
|
|
'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,
|
2020-12-02 19:16:22 +01:00
|
|
|
]
|
2020-12-01 17:02:10 +01:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|