0

enter image description here

This my sample 'publications' table structure. Currently, I am using the following code to view values.

@foreach($publications as $publication)
{{ $publication->title}} - Author: {{ $publication->author }}
@endforeach

Above code give me the following result.

enter image description here

Here, the titles of the first and third rows are the same. So I would like to merge them including the author as follows.

enter image description here Please help me to solve this issue. Thanks in advance.

Shaikhul Saad
  • 177
  • 2
  • 2
  • 12
  • Though this can be a temporary fix though I would suggest looking for removing the duplicacy in the tables itself https://stackoverflow.com/a/2613069/5192105 – Sachin Bahukhandi Jul 11 '20 at 15:41

1 Answers1

0

I think a better way to handle this is to restructure your database. Create two tables for title and author. In this case, I think the author can have many titles and titles can have many authors. If this is the case you need to have a pivot table for saving title id and author id. In laravel it many to many relationships. If a tile can have many authors and the author only can have one title it one to many relationships no need pivot table. It's up to your business logic. My advice here is to handle this in the database level rather than try to handle it in the controller or blade. I can be done in a blade or controller with some condition but in the future it can cause many problems. It's up to you.