- Add StatusResource for responses - Add OK & KO responses - Update composer.json for dependencies - Rename deleteUser to delete
45 lines
1.3 KiB
PHP
45 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,
|
|
'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,
|
|
]
|
|
];
|
|
}
|
|
}
|