mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Merge pull request #7668 from beganovich/expenses-relationships
Expenses relationships
This commit is contained in:
commit
99b1bc2505
@ -13,8 +13,10 @@ namespace App\Transformers;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Vendor;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use League\Fractal\Resource\Item;
|
||||
|
||||
/**
|
||||
* class ExpenseTransformer.
|
||||
@ -31,7 +33,10 @@ class ExpenseTransformer extends EntityTransformer
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = [];
|
||||
protected $availableIncludes = [
|
||||
'client',
|
||||
'vendor',
|
||||
];
|
||||
|
||||
public function includeDocuments(Expense $expense)
|
||||
{
|
||||
@ -40,6 +45,28 @@ class ExpenseTransformer extends EntityTransformer
|
||||
return $this->includeCollection($expense->documents, $transformer, Document::class);
|
||||
}
|
||||
|
||||
public function includeClient(Expense $expense): ?Item
|
||||
{
|
||||
$transformer = new ClientTransformer($this->serializer);
|
||||
|
||||
if (!$expense->client) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->includeItem($expense->client, $transformer, Client::class);
|
||||
}
|
||||
|
||||
public function includeVendor(Expense $expense): ?Item
|
||||
{
|
||||
$transformer = new VendorTransformer($this->serializer);
|
||||
|
||||
if (!$expense->vendor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->includeItem($expense->vendor, $transformer, Vendor::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Expense $expense
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user