To achieve the MySQL equivalent of a nested query using Laravel's Query Builder, you can use a subquery. Here's how you can modify your code to achieve this:
$details = DB::table('TABLE_A')
->leftJoin('TABLE_B', 'TABLE_A.username', '=', 'TABLE_B.username')
->select('TABLE_A.job_id', 'TABLE_A.payments_made', 'TABLE_A.username', 'TABLE_A.project_name', 'TABLE_A.location', 'TABLE_B.balance')
->where('TABLE_A.username', function ($query) use ($request) {
$query->select('username')
->from('TABLE_A')
->where('job_id', $request->job_id)
->limit(1);
})
->limit(1)
->get();
In the where clause, you can pass a closure to specify a subquery. Inside the closure, you can use the select, from, and where methods to build the subquery.
This way, you can achieve the desired result without making an additional query to fetch the username from TABLE_A.
Note: Make sure to replace 'TABLE_A' and 'TABLE_B' with the actual table names in your database.