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

t9dev's avatar
Level 2

Split table into equal number of rows in One Blade Page

For clarity, I have a list of 50 students and I want to split them into 5 table (10 rows each) to assign a supervisor.

Controller Function to allocate supervisor:

$student = DB::table('students')->skip(0)->take(PHP_INT_MAX)->get();
        $negeri = DB::table('students')
            ->where('Negeri', '=', $states)->orderBy('Poskod', 'desc')
			// what to add here ?
            ->get();
        $superviros = DB::table('supervisors')->get();
        return view('allocation', compact('student', 'negeri', 'superviros'))->with('states', $states);

What collection method would be useful?

0 likes
6 replies
t9dev's avatar
Level 2

@Snapey, yes. Each table will show 10 record each, meaning that I will be having 5 tables in a single blade. I have tried the limit(10) function, but I want it to loop it for the other records also.

Snapey's avatar

@t9dev Did you look at the docs for split() at all?

$group = $students->split(5);

in view

	@foreach($groups as $group)
	<table>
        @foreach($group as $student)
          <tr>
             <td>{{$student->name}}</td>
         </tr>
       @endforeach
    </table>
  @endforeach
t9dev's avatar
Level 2

@Snapey , I have tried it but as you can see I have 2 queries, one for the supervisor and the other on for the students ordered by stated.

Maybe you will understand if you see my blade view.

<div class="card">
                        <div class="card-header bgsize-primary-4 white card-header">
                                
                                <h4 class="card-title" style="padding-top: 10px">Student List Table in - {{$states}}</h4>
                                <select class="form-select" aria-label="Default select example">
                                    <option selected>Select a supervisor</option>
                                    @foreach ($superviros as $sv)
                                        <option value="{{$sv->id}}">{{$sv -> name}}</option>
                                    @endforeach
                                    
                                </select>   
                        </div>
                          
                        <div class="card-body">

                            <div class=" card-content table-responsive">

                                <table id="student_t" class="table table-hover table-bordered text-nowrap" style="width:100%">

                                    <thead>
                                        
                                        <th><input id="checkAll" type="checkbox" class="form-check-input check" /></th>
                                        <th>Bil</th>
                                        <th>No_Matrik</th>
                                        <th>No_KP</th>
                                        <th>Nama</th>
                                        
                                    </thead>
                                    

                                    <tbody>

                                    @if(!empty($negeri) && $negeri->count())

                                        @foreach($negeri as $row)
                                            <tr>
                                                
                                                <td> <input class="form-check-input check" type="checkbox" value="" id="flexCheckDefault"></td>
                                                <td>{{ $row->id }}</td>
                                                <td>{{ $row->No_Matrik }}</td>
                                                <td>{{ $row->No_KP }}</td>
                                                <td>{{ $row->Nama }}</td>
  
                                            </tr>

                                        @endforeach

                                    @else

                                        <tr>

                                            <td colspan="10">There are no data.</td>

                                        </tr>

                                    @endif

                                        
                                    </tbody>
                                    
                                </table>
                          
                            </div>
                            <button type="button" class="m-2 btn btn-primary">Assign Supervisor</button>
                        </div>
t9dev's avatar
Level 2

@Snapey , okay, thank you. I will try to make it in another way. Appreciated :)

Please or to participate in this conversation.