I have php function that compares two different database table. Any suggestion on improving it.     public function comparePartyTableCandidates()   {      $electionCandidates =  ElectionCandidate::all();      foreach($electionCandidates as $electionCandidate )      {         $candidateName = $electionCandidate->CandidateFirstname.  .$electionCandidate->CandidateLastname ;         $result = Candidate::where('candidateName' ,'=',$candidateName )->first();         if(empty($result))        {           $electionconstituency= ElectionConstituency::where('ConstituencyID', '=',$electionCandidate->ConstituencyID)->first();           $constituency = Constituency::where('ConstituencyName', '=',strtolower($electionconstituency->ConstituencyName))->first();            echo $electionconstituency->ConstituencyName;            if(empty($constituency))            {                if((preg_match(/KINGSTON EAST & PORT ROYAL/,$electionconstituency->ConstituencyName)))                {                    $constituency = Constituency::where('ConstituencyName', 'like',%.kingston Eastern)->first();                }            }           $electionparty = ElectionParty::where('PartyID', 'like', '%' . $electionCandidate->PartyID)->first();           $politicalParty = PoliticalParty::where('partyName', 'like', '%' . $electionparty->PartyAbbr)->first();           $candidate = new Candidate();           $candidate->candidateName = $candidateName;           $candidate->constituency_Id = $constituency->id;           $candidate->party_id = $politicalParty->id;           $candidate->save();         }      }   }
Compare 2 Different database Table
php;laravel;eloquent