Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ibe's avatar
Level 1

How to group multiple tables under the same date?

Hi there, does anyone know how to sort data per day from multiple tables?

So I have multiple tables (actone, acttwo, actthree,...). Each one of them contains the timestamps with the created_at. How can I group actone, acttwo, actthree,... under the same date? Can anyone help please?

How I would like my view: https://prnt.sc/j6f73w

ChildController:

public function show($id)
    {
      $child = Child::find($id);

      return view('admin.children.show')->withChild($child);
    }

Show.blade.php:

<?php foreach ($child->actone as $actone): ?>

          <td>{{$actone->category}}</td>
          <td>{{$actone->time}}</td>
          <td>{{$actone->name}}</td>
          <td>{{$actone->rating}}</td>
          <td>{{$actone->comment}}</td>
      <td>{{$actone->created_at}}</td>

        <?php endforeach; ?>


        <?php foreach ($child->acttwo as $acttwo): ?>

          <td>{{$acttwo->time_from}}</td>
          <td>{{$acttwo->time_to}}</td>
          <td>{{$acttwo->rating}}</td>
          <td>{{$acttwo->comment}}</td>
      <td>{{$acttwo->created_at}}</td>

        <?php endforeach; ?>

        <?php foreach ($child->actthree as $actthree): ?>

          <h1>{{$actthree->medication}}</h1>
          <h1>{{$actthree->time}}</h1>
          <h1>{{$actthree->prescription}}</h1>
          <h1>{{$actthree->comment}}</h1>
      <td>{{$actthree->created_at}}</td>

        <?php endforeach; ?>
    
    ...

Thanks!!

0 likes
5 replies
tykus's avatar

Isn't this the same problem as the other thread?

Ibe's avatar
Level 1

@tykus yh...because I still couldn't get it to work.. :(

tykus's avatar

I just gave you a possible solution on the other thread - give it a try

Cronix's avatar

It's generally frowned upon to create multiple threads of the same thing. It gets confusing too.

Please or to participate in this conversation.