jay_gorio
3 years ago
307
12
Laravel

Divide collection into parts on laravel

Posted 3 years ago by jay_gorio

I have this curriculum type of data that should be displayed and unequally divided. See this image

What I want is to achieve something like thisthis

Here's my code:

StudentController.php

public function show($id)
{
    $student = Student::with('course', 'course.curriculum', 'course.curriculum.subjects')->findOrFail($id);

    return view('students.show', compact('student'));
}

show.blade.php

<div class="panel-body">
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>Course Code</th>
                <th>Descriptive Title</th>
                <th>Units</th>
                <th>Prerequisites</th>
                <th>Grade</th>
            </tr>
        </thead>

        <tbody>
            @foreach($student->course->curriculum->subjects as $subject)
            <tr>
                <td>{{ $subject->subject_code }}</td>
                <td>{{ $subject->subject_description }}</td>
                <td>{{ $subject->units }}</td>
                <td></td>
                <td>98</td>
            </tr>
            @endforeach
        </tbody>
    </table>
</div>

Please sign in or create an account to participate in this conversation.