1
  $Report = Db::table('Attendance_Processed as procc')                            
                      ->leftjoin('Emp_Details', 'Emp_Details.HRApp_Emp_Id', '=', 'procc.HRApp_Emp_Id')
                            ->where('procc.Org_ID',$orgid)
                            ->where('Emp_Details.Supervisor_Emp_ID',$hrid)
                            ->whereYear('Clock_Day',$yearofdata)
                            ->whereMonth('Clock_Day',$monthofdata)   
                            ->select('Emp_Details.Emp_First_Name as name','procc.HRApp_Emp_Id as hrid',
                              'procc.Clock_Day as clockedday',
                              'procc.Time_in as timein',
                              'procc.Time_out as Timeout',
                              'procc.Total_Work_Hrs as totalworkedhours')


                           ->get()->groupBy('hrid','clockedday');
                           dd($Report);
                             return $Report;

the following code produce the this format

> Collection {#1168 ▼   #items: array:13 [▼
>     8 => Collection {#1155 ▼
>       #items: array:6 [▼
>         0 => {#934 ▼
>           +"name": "Aditi"
>           +"hrid": "8"
>           +"clockedday": "2017-10-03"
>           +"timein": "07:59:37"
>           +"Timeout": "16:52:30"
>           +"totalworkedhours": "08:52:53"
>         }
>         1 => {#935 ▼
>           +"name": "Aditi"
>           +"hrid": "8"
>           +"clockedday": "2017-10-04"
>           +"timein": "07:33:59"
>           +"Timeout": "16:31:48"
>           +"totalworkedhours": "08:57:49"
>         }
>         2 => {#936 ▶}
>         3 => {#937 ▶}
>         4 => {#938 ▶}
>         5 => {#939 ▶}
>       ]
>     }
>     20 => Collection {#1156 ▶}
>     213 => Collection {#1157 ▶}
>     11 => Collection {#1158 ▶}
>     22 => Collection {#1159 ▶}
>     10 => Collection {#1160 ▶}
>     9 => Collection {#1161 ▶}
>     28 => Collection {#1162 ▶}
>     29 => Collection {#1163 ▶}
>     16 => Collection {#1164 ▶}
>     17 => Collection {#1165 ▶}
>     25 => Collection {#1166 ▶}
>     31 => Collection {#1167 ▶}   ]

I am not able to print it properly on blade with foreachloop.

when i am trying to print it in blade file its showing the following error


"Property [hrid] does not exist on this collection instance".


please help me in this ..

Thank you in advance

Madhu Nair
  • 428
  • 1
  • 7
  • 20

1 Answers1

0

the first thing is that you have misplaced groupBy, it should be:

->groupBy('hrid','clockedday')->get();

check you have the correct data or not, then once you have the collection loop through it to print data within it.

in blade your file

@foreach ($result as $data)// loop through single object of collection
    {{ $data->hrid }} // or any other field
@endforeach

For collection within collection try like below

@foreach ($mainData as $result) // main collection
    @foreach ($result->secondCollection as $data)// variable containing second collection
        {{ $data->hrid }} // or any other field
    @endforeach
@endforeach

Also have a look on the reference link for looping through collection

Jigar Shah
  • 6,143
  • 2
  • 28
  • 41