company_id = $company_id; $this->db = $db; } public function handle() { MultiDB::setDb($this->db); $this->company = Company::find($this->company_id); $this->invoices = Invoice::where('company_id', $this->company->id) ->whereIn('status_id', [1,2,3]) ->where('is_deleted', 0) ->get(); $this->match(); } private function match() { BankTransaction::where('company_id', $this->company->id) ->where('status_id', BankTransaction::STATUS_UNMATCHED) ->cursor() ->each(function ($bt){ $invoice = $this->invoices->first(function ($value, $key) use ($bt){ return str_contains($bt->description, $value->number); }); if($invoice) { $bt->invoice_ids = $invoice->hashed_id; $bt->status_id = BankTransaction::STATUS_MATCHED; $bt->save(); } }); } }