Improvements for eager loading

This commit is contained in:
David Bomba 2023-04-24 20:35:26 +10:00
parent b292a843e4
commit 25d3c8d209
4 changed files with 9 additions and 5 deletions

View File

@ -545,7 +545,7 @@ class CreditController extends BaseController
}
});
return $this->listResponse(Credit::withTrashed()->company()->whereIn('id', $request->ids));
return $this->listResponse(Credit::with(['invitations','documents'])->withTrashed()->company()->whereIn('id', $request->ids));
}
public function action(ActionCreditRequest $request, Credit $credit, $action)

View File

@ -30,7 +30,10 @@ class TokenAuth
*/
public function handle($request, Closure $next)
{
if ($request->header('X-API-TOKEN') && ($company_token = CompanyToken::with(['user', 'company'])->where('token', $request->header('X-API-TOKEN'))->first())) {
if ($request->header('X-API-TOKEN') && ($company_token = CompanyToken::with([
'user' => [
'account',
], 'company'])->where('token', $request->header('X-API-TOKEN'))->first())) {
$user = $company_token->user;
$error = [
@ -51,7 +54,6 @@ class TokenAuth
return response()->json($error, 403);
}
/*
|
| Necessary evil here: As we are authenticating on CompanyToken,
@ -59,7 +61,6 @@ class TokenAuth
| us to decouple a $user and their attached companies completely.
|
*/
$truth = app()->make(TruthSource::class);
$truth->setCompanyUser($company_token->cu);

View File

@ -347,6 +347,10 @@ class RecurringInvoice extends BaseModel
'status',
];
protected $with = [
'client.company',
];
protected $touches = [];
public function getEntityType()

View File

@ -90,7 +90,6 @@ class RecurringInvoiceTransformer extends EntityTransformer
'po_number' => $invoice->po_number ?: '',
'date' => $invoice->date ?: '',
'last_sent_date' => $invoice->last_sent_date ?: '',
// 'next_send_date' => $invoice->next_send_date ?: '',
'next_send_date' => $invoice->next_send_date_client ?: '',
'due_date' => $invoice->due_date ?: '',
'terms' => $invoice->terms ?: '',