mardi 4 septembre 2018

PHP loop through data and print sections by grouping

So I have the following query:

$sections = Section::with(['subsections.tasks.companies'])->where('parent', NULL)->sorted()->get()->toArray();

This returns the following type of structure:

array:2 [▼
  0 => array:10 [▼
    "id" => 12
    "name" => "Chapter 1"
    "parent" => null
    "position" => 12
    "created_at" => "2018-05-10 16:43:04"
    "updated_at" => "2018-06-08 14:37:54"
    "completed" => false
    "subsections" => array:2 [▼
      0 => array:10 [▼
        "id" => 14
        "name" => "Subcatgeory 2"
        "parent" => 12
        "created_at" => "2018-05-10 16:52:28"
        "updated_at" => "2018-06-08 14:37:51"
        "completed" => false
        "tasks" => array:1 [▼
          0 => array:15 [▼
            "id" => 3
            "name" => "Another task"
            "active" => 1
            "created_at" => "2018-05-10 16:52:50"
            "updated_at" => "2018-05-14 09:33:32"
            "pivot" => array:2 [▶]
            "companies" => []
          ]
        ]
      ]
      1 => array:10 [▶]
    ]
  ]
  1 => array:10 [▶]
]

Which is basically, sections > subsections > tasks.

I then try to export this data into a html table but I want to group the data by task sections like this:

enter image description here

Where stage1 is the outer parent section name.

I have managed to print the parent sections in my view file:

<table class="table table-bordered">

    <tbody>
    <tr>
        <td>Customer</td>
        @foreach($sections as $section)
            <td></td>
        @endforeach
    </tr>

    <tr>
        <th></th>
        <th>Task 1</th>
        <th>Task 2</th>
        <th>Task 3</th>
        <th>Task 4</th>
    </tr>
    <tbody>

    <tr>
        <td></td>
        <td>Date time</td>
        <td>Date time</td>
        <td>Date time</td>
        <td>Date time</td>
    </tr>

    </tbody>
</table>

But I am struggling to print the data by grouping by the tasks like in the above screenshot because I have to stay in the main loop but have to break out of the <tr> tag. Can anyone help me achieve this?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2wPi7Ab
via IFTTT

Aucun commentaire:

Enregistrer un commentaire