1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Transformers/ClientTransformer.php
2019-03-29 08:35:35 +11:00

53 lines
1.0 KiB
PHP

<?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 ?: '',
];
}
}