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

Ibe's avatar
Level 1

How can I join 2 tables and sort them by date

Hi there, I don't really know how I can join two tables together in Laravel... Hopefully, someone can help here. So basically I have the regulars table and the commemoratives table. I would like all the items and show them by date. So now there are separate from each other, but how can I merge/join them together?

Controller:

  public function getAll(){
    $regulars = Regular::all();
    $commemoratives = Commemorative::all();

    return view('pages/all')->withRegulars($regulars)->withCommemoratives($commemoratives);
  }

blade:

  @foreach ($regulars as $regular)


  @endforeach


  @foreach ($commemoratives as $commemorative)


  @endforeach

Thanks!!

0 likes
3 replies
jlrdw's avatar

And to add it would not hurt to view the absolutely at no cost free training videos Jeffrey has provided.

And if language is any barrier much of the code is available free on GitHub.

Many examples that would point you in the right direction.

Please or to participate in this conversation.