1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Added products to the API

This commit is contained in:
Hillel Coren 2015-11-19 13:50:35 +02:00
parent 01946f7bc8
commit d35b0f7f35
3 changed files with 31 additions and 1 deletions

View File

@ -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');

View File

@ -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 [

View File

@ -0,0 +1,18 @@
<?php namespace App\Ninja\Transformers;
use App\Models\Product;
use League\Fractal;
class ProductTransformer extends EntityTransformer
{
public function transform(Product $product)
{
return [
'id' => (int) $product->public_id,
'product_key' => $product->product_key,
'notes' => $product->notes,
'cost' => $product->cost,
'qty' => $product->qty,
];
}
}