Home > Software design >  How to access attributes in Laravel Eloquent Model
How to access attributes in Laravel Eloquent Model

Time:07-19

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');

CodePudding user response:

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
  • Related