0

I want to create a pagination for post controller, this is my route:

Route::get('post/{page?}' , 'PostController@Test');

And my action:

public function Test($page = 1)
{
    $tests = Test::paginate(15, ['*'], 'page', $page);

    foreach ($tests as $test) {
        echo $test->id;
    }

    echo $tests->render();
}

Now I can go to http://127.0.0.1:8000/post/2 to open page 2, but my pagination url looks like http://127.0.0.1:8000/post?page=2

Can i fix this?

Masoud92m
  • 602
  • 1
  • 8
  • 24

1 Answers1

0

As far as I know, it is not possible to introduce pretty URL for Pagination in Laravel without using external Package.

In one of my project, I was able to build the same using Laravel Paginateroute Package.

which you can install by this command :

composer require spatie/laravel-paginateroute

I have followed the Documentation provided by the author to implement the same.