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:
parent
01946f7bc8
commit
d35b0f7f35
@ -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');
|
||||
|
@ -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 [
|
||||
|
18
app/Ninja/Transformers/ProductTransformer.php
Normal file
18
app/Ninja/Transformers/ProductTransformer.php
Normal 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,
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user