Home > Blockchain >  How to Filter based on get() eloquent array
How to Filter based on get() eloquent array

Time:12-08

I Have the following array, and I would to display it in a blade file

The data from index which is 0 is supposed to be in a different table and the rest of the data starting from index 1 has to be in another table like below;

Subject Name Subject Average
English 40%
Geography 60%
History 70%
Literature 40%
Array (
 [0] => stdClass Object 
 ( [name] => George
    [student_id] => 238
    [lastname] => Smith 
    [middlename] => John
    [grade_name] => Grade 2A
    [stream_name] => Grade 2 
    [section_name] => Junior 
    [student_average] => 69
    [number_of_passed_subjects] => 8 
    [passing_subject_status] => 1
  )

[1] => stdClass Object 
( [student_average] => 56
[subject_name] => English In Literature 
[student_id] => 238 
)

[2] => stdClass Object ( [student_average] => 65 [subject_name] => Geography [student_id] => 238 )
[3] => stdClass Object ( [student_average] => 64 [subject_name] => Mathametics [student_id] => 238 )
[4] => stdClass Object ( [student_average] => 74 [subject_name] => SiSwati [student_id] => 238 )
[5] => stdClass Object ( [student_average] => 66 [subject_name] => Science [student_id] => 238 ) 
[6] => stdClass Object ( [student_average] => 80 [subject_name] => Home Economics [student_id] => 238 )
[7] => stdClass Object ( [student_average] => 45 [subject_name] => Additional Mathematics [student_id] => 238 )
[8] => stdClass Object ( [student_average] => 82 [subject_name] => Religious Education [student_id] => 238 )
[9] => stdClass Object ( [student_average] => 72 [subject_name] => History [student_id] => 238 ) 

)

How can i do this in blade?

I have tried using foreach but it only works for data in index 0

CodePudding user response:

<table>
  <tr>
    <th> Subject Name </th>
    <th> Subject Average </th>
  </tr>
  @foreach($array as $index=>$item)
    @if($index != 0)
      <tr>
         <td> {{ $item->subject_name }} </td>
         <td> {{ $item->subject_average }} </td>
      </tr>
    @endif
  @endforeach
</table>
  • Related