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) public function action(ActionCreditRequest $request, Credit $credit, $action)

View File

@ -30,7 +30,10 @@ class TokenAuth
*/ */
public function handle($request, Closure $next) 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; $user = $company_token->user;
$error = [ $error = [
@ -51,7 +54,6 @@ class TokenAuth
return response()->json($error, 403); return response()->json($error, 403);
} }
/* /*
| |
| Necessary evil here: As we are authenticating on CompanyToken, | 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. | us to decouple a $user and their attached companies completely.
| |
*/ */
$truth = app()->make(TruthSource::class); $truth = app()->make(TruthSource::class);
$truth->setCompanyUser($company_token->cu); $truth->setCompanyUser($company_token->cu);

View File

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

View File

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