0

I have a table:

name date1 date2
John 2020 2021
Adam 2022 2023
Peter 2024 2025

I would like to display every date values in a single record.

This is the result I would like to have is:

John  2020
John  2021
Adam  2022
Adam  2023
Peter 2024
Peter 2025

How to write a loop for this in Laravel?

UPDATE

I would like to sort the results by desc. How to do that?

2
  • 1
    We'd need to see the code that produced the table to begin with... Commented Oct 8, 2022 at 22:54
  • I would like to sort the results, so writing like what Quiet Molly suggested is not good. Commented Oct 8, 2022 at 23:07

1 Answer 1

0

The answer is rather preety simple, it really depends from Your Model

@foreach ($records as $record)
$record->name + " " + $record->date1
$record->name + " " + $record->date2
@endforeach

If this isnt what You are looking for, then please try providing more data and ask better question :c

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.