I am working on a financial management system where I have two tables, “Funds” and “FundingSources”. I want to retrieve information about each fund, including information from the “FundingSources” table, such as the source name, estimated cost, contract value, and party name. However, some funds may not have a corresponding funding source yet, and I still want to display the fund information in these cases.
$funds = DB::table('funds')
->select('funds.id', 'funds.package_code', 'funds.amount', 'funds.method', 'funding_sources.name',
'.funding_sources.estimated_cost', 'funding_sources.contract_value', 'funding_sources.party_name')
->join('funding_sources', 'funding_sources.id', '=', 'funds.funding_source_id')->get();
When I run my code using Laravel’s Eloquent with a JOIN, I only get the records where there is a match in both tables. But I need to display all the records from the “Funds” table even if there is no corresponding record in the “FundingSources” table. How can I fix this problem and get all the records?