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

wahyu_87's avatar

How to write blade view with pagination

how to write in blade view table with pagination like this

<table>

<tr>
    <td rowspan='3' colspan='2' >Header article</td>
    <td>article 1</td>
    <td>article 2</td>
</tr>
<tr>
    <td>article 3</td>
    <td>article 4</td>
</tr>
<tr>
    <td>article 5</td>
    <td>article 6</td>
</tr>
<tr>
    <td>article 7</td>
    <td>article 8</td>
    <td>article 9</td>
    <td>article 10</td>
</tr>
<tr>
    <td>article 11</td>
    <td>article 12</td>
    <td>article 13</td>
    <td>article 14</td>
</tr>
</table>

this is my controller

<?php
namespace App\Http\Controllers;
use App\Services\ArtikelService;
use App\Models\Artikel;
use Illuminate\Http\Request;
use DB;
class ArtikelController extends Controller
{
function artikel()
    {
        
        $artikels = DB::table('artikels')->paginate(14);

        return view('/artikel', ['artikels' => $artikels]);



   
    }
}

and this is my route

Route::get('/artikel', 'ArtikelController@artikel');

thank for help.

0 likes
10 replies
wahyu_87's avatar

thnk jlrdw for rply, i mean,i want to looping with pagination so output table like this

<table>

<tr>
    <td rowspan='3' colspan='2' >Header article</td>
    <td>article 1</td>
    <td>article 2</td>
</tr>
<tr>
    <td>article 3</td>
    <td>article 4</td>
</tr>
<tr>
    <td>article 5</td>
    <td>article 6</td>
</tr>
<tr>
    <td>article 7</td>
    <td>article 8</td>
    <td>article 9</td>
    <td>article 10</td>
</tr>
<tr>
    <td>article 11</td>
    <td>article 12</td>
    <td>article 13</td>
    <td>article 14</td>
</tr>
</table>
Snapey's avatar

Your time would be better spent learning css grids

Not sure what pagination has to do with it?

thewebartisan7's avatar

I think you want this:

// I suppose your article has an ID, title and content, otherwise change it
<table>

<tr>
    <th>ID</th>
    <th>Title</th>
    <ht>Content</th>
</tr>
@foreach($artikels as $artikel)
<tr>
    <td>{{$artikel->id}}</td>
    <td>{{$artikel->title}}</td>
    <td>{{$artikel->content}}</td>
</tr>
@endforeach
</table>
{{ $artikels->links() }}

But as Snapey suggest, maybe start learning how to build a table firstly, as your posted table show that you don't understand how it works.

See here https://www.w3schools.com/html/html_tables.asp

thewebartisan7's avatar

Then check my code example, there is the loop "foreach" that you are looking for.

wahyu_87's avatar

thanks all for reply,

so in laravel can't loop like this

this is the second page

<table>

<tr>
    <td rowspan='3' colspan='2' >Header article</td>
    <td>article 15</td>
    <td>article 16</td>
</tr>
<tr>
    <td>article 17</td>
    <td>article 18</td>
</tr>
<tr>
    <td>article 19</td>
    <td>article 20</td>
</tr>
<tr>
    <td>article 21</td>
    <td>article 22</td>
    <td>article 23</td>
    <td>article 24</td>
</tr>
<tr>
    <td>article 25</td>
    <td>article 26</td>
    <td>article 27</td>
    <td>article 28</td>
</tr>
</table>

so i must learning css grids, thanks all

saurav77's avatar

@wahyu_87

@foreach($datas as $key => $data)
  <tr>
     @if ($key == 0 || $key % 3 == 0)
         <td rowspan="3">{{$data->article_name}}</td>
     @endif
     <td>{{$data->article_name}}</td>
    
  </tr>
@endforeach
Snapey's avatar

your view does not care which page it is on. It receives an array of articles that are zero based, irrespective of page number. You could hard code it for instance;

<table>

<tr>
    <td rowspan='3' colspan='2' >Header article</td>
    <td>articles[0]</td>
    <td>articles[1]</td>
</tr>
<tr>
    <td>articles[2]</td>
    <td>articles[3]</td>
</tr>
<tr>
    <td>articles[4]</td>
    <td>articles[5]</td>

etc

page 2 would be identical....

Please or to participate in this conversation.