ldc-crm/app/Http/Resources/CustomerResource.php
2021-03-12 11:07:33 +01:00

46 lines
1.3 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class CustomerResource extends JsonResource
{
private $brandId;
public function __construct($resource, $brandId) {
parent::__construct($resource);
$this->brandId = $brandId;
}
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
$infos = $this->infos()->where('brand_id', $this->brandId)->first();
$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,
'city' => $infos->city,
'postcode' => $infos->postcode,
'opt_in' => $infos->opt_in,
'hashcode' => $infos->hashcode,
'status' => $login->status,
]
];
}
}