'How to get relative data for each row Laravel?

I have the following request:

$results = ResultTest::with("client", "doctor.distributor")
    ->whereIn("client_id", $transaction_items_unique_codes)
    ->get();

It returns me array of result. After I need to get additional data for each returned array item and join it to one result:

foreach ($results as $result) {
    $conclusion = Conclusion::where("type_work", $result->type_work)
        ->where("category", $result->category)
        ->firstOrFail();
    
    $types = Work::orderBy('name')->get()->pluck('name', 'id');
}

Problem is $results contains more 100 rows, so it has issues with 100 requests to db.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source