1
0
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:
David Bomba 2022-07-22 12:57:28 +10:00 committed by GitHub
commit 99b1bc2505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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