I have a database in which there are two tables driver_company_map
and company
what i do is i get company_code
from driver_company_map
table and i pass it in the where clause of another query which i perform on company
table my both separate query works like this
$result = DB::connection($this->masterDb)->table('driver_company_map')
->where('driver_code', $driverCode) //i get the $driverCode from function parameter
->select('company_code')
->first();
$companyCode = $result->company_code;
I use the above $companyCode
in the below query
$result = DB::connection($this->masterDb)->table('company')
->where('code', $companyCode)
->select('db_connection')
->first();
$clientDb = $result->db_connection;
The above logic works fine but i want both as nested query i tried it but not giving the correct result below is my code
$result = DB::connection($this->masterDb)->table('company')
->where('code', function($companyCode_query){
$companyCode_query->select('company_code')
->from('driver_company_map')
>where('driver_code', $driverCode);
})->get()
->select('db_connection')
->first();
$clientDb = $result->db_connection;