From d35b0f7f3514c03b3fc6f4a461daa8649f4be5c7 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 19 Nov 2015 13:50:35 +0200 Subject: [PATCH] Added products to the API --- app/Models/Account.php | 5 +++++ app/Ninja/Transformers/AccountTransformer.php | 9 ++++++++- app/Ninja/Transformers/ProductTransformer.php | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/Ninja/Transformers/ProductTransformer.php diff --git a/app/Models/Account.php b/app/Models/Account.php index a936c0227b..7d9d15d992 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -80,6 +80,11 @@ class Account extends Eloquent return $this->hasMany('App\Models\TaxRate'); } + public function products() + { + return $this->hasMany('App\Models\Product'); + } + public function country() { return $this->belongsTo('App\Models\Country'); diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index bbc4f4df9d..7e50baff9e 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -3,6 +3,7 @@ use App\Models\Account; use App\Models\AccountToken; use App\Models\Contact; +use App\Models\Product; use League\Fractal; use League\Fractal\TransformerAbstract; @@ -12,7 +13,8 @@ class AccountTransformer extends TransformerAbstract 'users', 'clients', 'invoices', - 'contacts' + 'contacts', + 'products', ]; public function includeUsers(Account $account) @@ -35,6 +37,11 @@ class AccountTransformer extends TransformerAbstract return $this->collection($account->contacts, new ContactTransformer($account)); } + public function includeProducts(Account $account) + { + return $this->collection($account->products, new ProductTransformer($account)); + } + public function transform(Account $account) { return [ diff --git a/app/Ninja/Transformers/ProductTransformer.php b/app/Ninja/Transformers/ProductTransformer.php new file mode 100644 index 0000000000..3727d42a8a --- /dev/null +++ b/app/Ninja/Transformers/ProductTransformer.php @@ -0,0 +1,18 @@ + (int) $product->public_id, + 'product_key' => $product->product_key, + 'notes' => $product->notes, + 'cost' => $product->cost, + 'qty' => $product->qty, + ]; + } +} \ No newline at end of file