From 8aeabb7e1f80f358a24ca64f8aef04b8bcd8bc2c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 7 Dec 2021 22:34:50 +1100 Subject: [PATCH] Performance improvements for Client Portal --- app/Http/Controllers/Auth/ContactLoginController.php | 9 ++++----- app/Http/Livewire/InvoicesTable.php | 1 + app/Http/Livewire/QuotesTable.php | 1 + app/Http/Middleware/CheckClientExistence.php | 2 +- app/Http/Middleware/ContactRegister.php | 7 ++++--- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Auth/ContactLoginController.php b/app/Http/Controllers/Auth/ContactLoginController.php index 3cba611befb5..d3d2e4fc05ec 100644 --- a/app/Http/Controllers/Auth/ContactLoginController.php +++ b/app/Http/Controllers/Auth/ContactLoginController.php @@ -42,16 +42,15 @@ class ContactLoginController extends Controller if($request->has('company_key')){ MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); - $company = Company::where('company_key', $request->input('company_key'))->first(); - } - - if (!$company && strpos($request->getHost(), 'invoicing.co') !== false) { + if($company){ + $account = $company->account; + } + elseif (!$company && strpos($request->getHost(), 'invoicing.co') !== false) { $subdomain = explode('.', $request->getHost())[0]; MultiDB::findAndSetDbByDomain(['subdomain' => $subdomain]); - $company = Company::where('subdomain', $subdomain)->first(); } elseif(Ninja::isHosted()){ diff --git a/app/Http/Livewire/InvoicesTable.php b/app/Http/Livewire/InvoicesTable.php index 5e296e28e2ad..68351ecf5919 100644 --- a/app/Http/Livewire/InvoicesTable.php +++ b/app/Http/Livewire/InvoicesTable.php @@ -43,6 +43,7 @@ class InvoicesTable extends Component $local_status = []; $query = Invoice::query() + ->with('client.gateway_tokens','company','client.contacts') ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->where('company_id', $this->company->id) ->where('is_deleted', false); diff --git a/app/Http/Livewire/QuotesTable.php b/app/Http/Livewire/QuotesTable.php index eaf9a0add6c1..f52ee96fd945 100644 --- a/app/Http/Livewire/QuotesTable.php +++ b/app/Http/Livewire/QuotesTable.php @@ -38,6 +38,7 @@ class QuotesTable extends Component public function render() { $query = Quote::query() + ->with('client.gateway_tokens','company','client.contacts') ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc'); if (count($this->status) > 0) { diff --git a/app/Http/Middleware/CheckClientExistence.php b/app/Http/Middleware/CheckClientExistence.php index a80dc0496543..20b3ad5a3475 100644 --- a/app/Http/Middleware/CheckClientExistence.php +++ b/app/Http/Middleware/CheckClientExistence.php @@ -29,7 +29,7 @@ class CheckClientExistence public function handle(Request $request, Closure $next) { $multiple_contacts = ClientContact::query() - ->with('company','client') + ->with('client.gateway_tokens') ->where('email', auth('contact')->user()->email) ->whereNotNull('email') ->where('email', '<>', '') diff --git a/app/Http/Middleware/ContactRegister.php b/app/Http/Middleware/ContactRegister.php index ade62aa84974..c76df09a582b 100644 --- a/app/Http/Middleware/ContactRegister.php +++ b/app/Http/Middleware/ContactRegister.php @@ -19,10 +19,11 @@ class ContactRegister */ public function handle($request, Closure $next) { + $domain_name = $request->getHost(); - if (strpos($request->getHost(), 'invoicing.co') !== false) + if (strpos($domain_name, 'invoicing.co') !== false) { - $subdomain = explode('.', $request->getHost())[0]; + $subdomain = explode('.', $domain_name)[0]; $query = [ 'subdomain' => $subdomain, @@ -86,6 +87,6 @@ class ContactRegister return $next($request); } - abort(404, 'ContactRegister Middlware'); + abort(404, 'ContactRegister Middleware'); } }