Laravel joins using different database query

I am constructing this query in my Laravel controller;

$payments = DB::table('payments')->leftJoin('postcodes.201502_postcode', 'payments.Vendor ZIP', '=', '201502_postcode.postcode'); foreach ($input as $key => $value) { $payments = $payments->leftJoin('postcodes.pc_'.$key, '201502_postcode.'.$key, '=', 'pc_'.$key.'', 'code'); } foreach ($input as $key => $value) { $payments = $payments->orWhereIn('pc_'.$key.'.code', $input[$key]); } $payments = $payments->select('Vendor ZIP' , 'Input RAC' , 'Input LPC Code' , 'Input UIN Code')->get();

An example $input looks like this;

Array ( [county] => Array ( [0] => E10000003 [1] => E10000006 ) [locauth] => Array ( [0] => E07000223 [1] => E07000032 ) [parlc] => Array ( [0] => W07000058 [1] => S14000003 )

)

There are 5 fields in total. Not all five fields are required though. Above, "the User" is only searching on 3 for example.

The error I get is Unknown column 'pc_county' in 'on clause'. I'm not sure where to put my dots. Can I escape the dots?

It's getting confusing because the 201502_postcode table is in the postcodes database... and that table has a postcode field. The pc_xxxxx tables are also in this same postcodes database.

This is in a separate db to the payments table.

Category:php Views:5 Time:2019-02-11

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.149 (s). 12 q(s)