0

I have this code I get everything I want here but everything goes to attribute, but I don't know how can I access my reportItems in attributes of these arrays?

Screenshot

$reportsGrouped = collect($pharmacy->pharmacyReportIndetificator->reportItem->map(function($item){    
            return $item->report;
        }))->unique('report_id')->map(function($report) use($pharmacy) {
            $reportItems = ReportItem::where(['report_id' => $report->report_id, 'report_pharmacy_pib_code' => $pharmacy->pharmacyReportIndetificator->pharmacy_pib])->get();
            $reportItemsSum = $reportItems->sum('report_product_sum');

            $report->reportItemsSum = $reportItemsSum;
            $report->reportItems = $reportItems;

            return $report;
        })->sortBy('report_date')->groupBy('report_date');

2 Answers 2

1

You have the collection of items.

You can loop through the collection returned by querying and access any attribute.

Following is the code you can use in your blade:

@foreach($items as $item)  
 @foreach($item->reportItems as $reportItem) 
  {{ $reportItem->somePropertyPfReportItem }}  
 @endforeach 
@endforeach
Sign up to request clarification or add additional context in comments.

Comments

0

if result has one record for accessing to your item you can use this:

$value->first()->reportItem

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.