From 34bbeeb1460bd66d9306514225cd7acc1a209600 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 29 Mar 2019 08:35:35 +1100 Subject: [PATCH] Add Transformers --- app/Transformers/ArraySerializer.php | 33 ++++++++++++ app/Transformers/ClientContactTransformer.php | 35 +++++++++++++ app/Transformers/ClientTransformer.php | 52 +++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 app/Transformers/ArraySerializer.php create mode 100644 app/Transformers/ClientContactTransformer.php create mode 100644 app/Transformers/ClientTransformer.php diff --git a/app/Transformers/ArraySerializer.php b/app/Transformers/ArraySerializer.php new file mode 100644 index 0000000000..8b54878116 --- /dev/null +++ b/app/Transformers/ArraySerializer.php @@ -0,0 +1,33 @@ + (int) $contact->public_id, + 'first_name' => $contact->first_name ?: '', + 'last_name' => $contact->last_name ?: '', + 'email' => $contact->email ?: '', + 'updated_at' => $contact->updated_at, + 'archived_at' => $contact->deleted_at, + 'is_primary' => (bool) $contact->is_primary, + 'phone' => $contact->phone ?: '', + 'custom_value1' => $contact->custom_value1 ?: '', + 'custom_value2' => $contact->custom_value2 ?: '', + ]; + } +} diff --git a/app/Transformers/ClientTransformer.php b/app/Transformers/ClientTransformer.php new file mode 100644 index 0000000000..a4f2b8a26e --- /dev/null +++ b/app/Transformers/ClientTransformer.php @@ -0,0 +1,52 @@ +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 ?: '', + ]; + } +}