I have data that I need to display in 3 rows with header in Laravel blade view.I know there is chunk method in Laravel to chunk the data and display.But I want to diplay data in different way.
Here is my data
Illuminate\Support\Collection {#1898 ▼
#items: array:2 [▼
0 => {#1021 ▼
+"parameter": "NH3 Examine"
+"id": 6
+"pond_quality_id": 5
+"parameter_id": 28
+"pond_water_cig": 12
+"pond_water_non_cig": 12
+"taken_actions_cig": 12
+"taken_actions_non_cig": 12
+"taken_actions": "action"
+"measure_before_intervention": "before"
+"measure_after_intervention": "after"
+"remarks": "remarks1"
+"created_at": "2021-04-25 10:16:00"
+"updated_at": "2021-04-25 10:16:00"
}
1 => {#1897 ▼
+"parameter": "O2 Examine"
+"id": 7
+"pond_quality_id": 5
+"parameter_id": 29
+"pond_water_cig": 23
+"pond_water_non_cig": 23
+"taken_actions_cig": 23
+"taken_actions_non_cig": 23
+"taken_actions": "action taken"
+"measure_before_intervention": "before intervention"
+"measure_after_intervention": "after intervention"
+"remarks": "remarks2"
+"created_at": "2021-04-25 10:16:00"
+"updated_at": "2021-04-25 10:16:00"
}
]
}
Here is how I want to output my data
| col1 | col2 | col3 | col4 |
|---|---|---|---|
| col1 val1 | col2 val1 | col3 val3 | col4 val4 |
| col1 val2 | col2 val2 | col3 val3 | col4 val4 |
| col5 | col6 | col7 | col8 |
|---|---|---|---|
| col5 val1 | col6 val1 | col7 val3 | col8 val4 |
| col5 val2 | col6 val2 | col7 val3 | col8 val4 |
| col9 |
|---|
| col9 val1 |
| col9 val2 |
How can I achieve this?
You have
$loopin scope for every@foreachloop you use in blade, that also scales with loops inside of loopsHere's an example of how you could achieve what you want; every 3rd row, add a header of your choice. You might need to play with the modulus there - I'm sure 3 is correct, but considering
$loop->iterationstarts at 1, not 0, I could be wrong.Please see: https://laravel.com/docs/8.x/blade for more usages of
$loop variablewithin the context of@foreachYou need to define yourself a set of rules for your header rows, considering you have 3 identical tables, but your fourth seems to have 1 header and is unique, you may want to create a helper function that allows you to include a view dependant on the iteration using more than one
@ifstatement in your blade.