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

habib001's avatar

How to convert row data to column data in laravel

Hi I need a help. I have three table one for tbl_student_registration, one for tbl_subject and another for subject mark. I need to display by converting row data to column data with joining table. How can do this

0 likes
2 replies
Vilfago's avatar

Short answer : with <td> tags.

Long answer will need example of data you have in your DB, and an example of the output you want.

QuentinWatt's avatar

Assuming 'tbl_student_registration' is the table with your user's, and your 'subject table' has a relationship set up with 'tbl_student_registration". (also assuming your 'mark' would be in the 'subjects' table.)

You can do something like this:

$subjects = Subject::with('student_registration');

return view('whatever_your_view_is')->with([
    'subjects' => $subjects,
]);

<table>
        <tr>
               <th>Student name</th>
               <th>Subject</th>
               <th>Mark</th>
        </tr>
        @foreach($subjects as $subject)
        <tr>
               <td>{{$subject->student_registration->nameOfStudent}}</td>
               <th>{{$subject->nameOfSubject}}</th>
               <th>{{$subject->mark}}</th>
        </tr>
       @endforeach
</table>

However you have not explained much about your database set up, so all of this is pure conjecture.

Please or to participate in this conversation.