1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Transformers/ClientTransformer.php

53 lines
1.0 KiB
PHP
Raw Normal View History

2019-03-28 22:35:35 +01:00
<?php
namespace App\Transformers;
use App\Models\Client;
use App\Models\ClientContact;
/**
* @SWG\Definition(definition="Client", @SWG\Xml(name="Client"))
*/
class ClientTransformer extends EntityTransformer
{
/**
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
*/
protected $defaultIncludes = [
'contacts',
];
/**
* @var array
*/
protected $availableIncludes = [
];
/**
* @param Client $client
*
* @return \League\Fractal\Resource\Collection
*/
public function includeContacts(Client $client)
{
$transformer = new ClientContactTransformer($this->serializer);
return $this->includeCollection($client->contacts, $transformer, ClientContact::class);
}
/**
* @param Client $client
*
* @return array
*/
public function transform(Client $client)
{
return [
'id' => (int) $client->id,
'name' => $client->name ?: '',
];
}
}